JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>w3c.dom.Element; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.w3c.dom.ProcessingInstruction; /** * A Pointer that points to a DOM node. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class DOMNodePointer extends NodePointer { private static final long serialVersionUID = -8751046933894857319L; private Node node; private Map namespaces; private String defaultNamespace; private String id; public static final String XML_NAMESPACE_URI = "http://www.w3.org/XML/1998/namespace"; public static final String XMLNS_NAMESPACE_URI = "http://www.w3.org/2000/xmlns/"; public DOMNodePointer(Node node, Locale locale) { super(null, locale); this.node = node; } public DOMNodePointer(Node node, Locale locale, String id) { super(null, locale); this.node = node; this.id = id; } public DOMNodePointer(NodePointer parent, Node node) { super(parent); this.node = node; } public boolean testNode(NodeTest test) { return testNode(node, test); } public static boolean testNode(Node node, NodeTest test) { if (test == null) { return true; } if (test instanceof NodeNameTest) { if (node.getNodeType() != Node.ELEMENT_NODE) { return false; } NodeNameTest nodeNameTest = (NodeNameTest) test; QName testName = nodeNameTest.getNodeName(); String namespaceURI = nodeNameTest.getNamespaceURI(); boolean wildcard = nodeNameTest.isWildcard(); String testPrefix = testName.getPrefix(); if (wildcard && testPrefix == null) { return true; } if (wildcard || testName.getName() .equals(DOMNodePointer.getLocalName(node))) { String nodeNS = DOMNodePointer.getNamespaceURI

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>(node); return equalStrings(namespaceURI, nodeNS); } return false; } if (test instanceof NodeTypeTest) { int nodeType = node.getNodeType(); switch (((NodeTypeTest) test).getNodeType()) { case Compiler.NODE_TYPE_NODE : return nodeType == Node.ELEMENT_NODE || nodeType == Node.DOCUMENT_NODE; case Compiler.NODE_TYPE_TEXT : return nodeType == Node.CDATA_SECTION_NODE || nodeType == Node.TEXT_NODE; case Compiler.NODE_TYPE_COMMENT : return nodeType == Node.COMMENT_NODE; case Compiler.NODE_TYPE_PI : return nodeType == Node.PROCESSING_INSTRUCTION_NODE; } return false; } if (test instanceof ProcessingInstructionTest) { if (node.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) { String testPI = ((ProcessingInstructionTest) test).getTarget(); String nodePI = ((ProcessingInstruction) node).getTarget(); return testPI.equals(nodePI); } } return false; } private static boolean equalStrings(String s1, String s2) { if (s1 == s2) { return true; } s1 = s1 == null ? "" : s1.trim(); s2 = s2 == null ? "" : s2.trim(); return s1.equals(s2); } public QName getName() { String ln = null; String ns = null; int type = node.getNodeType(); if (type == Node.ELEMENT_NODE) { ns = DOMNodePointer.getPrefix(node); ln = DOMNodePointer.getLocalName(node); } else if (type == Node.PROCESSING_INSTRUCTION_NODE) { ln = ((ProcessingInstruction) node).getTarget(); } return new QName(ns, ln); } public String getNamespaceURI() { return getNamespaceURI(node); } public NodeIterator childIterator( NodeTest test, boolean reverse, NodePointer startWith) { return new DOMNodeIterator(this, test, reverse, startWith); } public NodeIterator attributeIterator(QName name) { return new DOMAttributeIterator(

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>this, name); } public NodePointer namespacePointer(String prefix) { return new NamespacePointer(this, prefix); } public NodeIterator namespaceIterator() { return new DOMNamespaceIterator(this); } public String getNamespaceURI(String prefix) { if (prefix == null || prefix.equals("")) { return getDefaultNamespaceURI(); } if (prefix.equals("xml")) { return XML_NAMESPACE_URI; } if (prefix.equals("xmlns")) { return XMLNS_NAMESPACE_URI; } String namespace = null; if (namespaces == null) { namespaces = new HashMap(); } else { namespace = (String) namespaces.get(prefix); } if (namespace == null) { String qname = "xmlns:" + prefix; Node aNode = node; if (aNode instanceof Document) { aNode = ((Document)aNode).getDocumentElement(); } while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { namespace = attr.getValue(); break; } } aNode = aNode.getParentNode(); } if (namespace == null || namespace.equals("")) { namespace = NodePointer.UNKNOWN_NAMESPACE; } } namespaces.put(prefix, namespace); if (namespace == UNKNOWN_NAMESPACE) { return null; } // TBD: We are supposed to resolve relative URIs to absolute ones. return namespace; } public String getDefaultNamespaceURI() { if (defaultNamespace == null) { Node aNode = node; if (aNode instanceof Document) { aNode = ((Document) aNode).getDocumentElement(); } while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode("xmlns"); if (attr != null) { defaultNamespace = attr.getValue(); break; } } aNode = aNode.getParentNode(); } } if (defaultNamespace == null) { defaultNamespace = ""; } // TBD: We are supposed to

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS> resolve relative URIs to absolute ones. return defaultNamespace.equals("") ? null : defaultNamespace; } public Object getBaseValue() { return node; } public Object getImmediateNode() { return node; } public boolean isActual() { return true; } public boolean isCollection() { } else { node.getParentNode().removeChild(node); } } else { NodeList children = node.getChildNodes(); int count = children.getLength(); for (int i = count; --i >= 0;) { Node child = children.item(i); node.removeChild(child); } if (value instanceof Node) { Node valueNode = (Node) value; if (valueNode instanceof Element || valueNode instanceof Document) { children = valueNode.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); node.appendChild(child.cloneNode(true)); } } else { node.appendChild(valueNode.cloneNode(true)); } } else { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { Node textNode = node.getOwnerDocument().createTextNode(string); node.appendChild(textNode); } } } } public NodePointer createChild( JXPathContext context, QName name, int index) { if (index == WHOLE_COLLECTION) { index = 0; } boolean success = getAbstractFactory(context).createObject( context, this, node, name.toString(), index); if (success) { NodeTest nodeTest; String prefix = name.getPrefix(); String namespaceURI = prefix != null ? context.getNamespaceURI(prefix) : context.getDefaultNamespaceURI(); nodeTest = new NodeNameTest(name, namespaceURI); NodeIterator it = childIterator(nodeTest, false, null); if (it != null && it.setPosition(index + 1)) { return it.getNodePointer(); } } throw new JXPathAbstractFactoryException( "Factory could not create a child

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS> node for path: " + asPath() + "/" + name + "[" + (index + 1) + "]"); } public NodePointer createChild(JXPathContext context, QName name, int index, Object value) { NodePointer ptr = createChild(context, name, index); ptr.setValue(value); return ptr; } public NodePointer createAttribute(JXPathContext context, QName name) { if (!(node instanceof Element)) { return super.createAttribute(context, name); } Element element = (Element) node; String prefix = name.getPrefix(); if (prefix != null) { String ns = getNamespaceURI(prefix); if (ns == null) { throw new JXPathException( "Unknown namespace prefix: " + prefix); } element.setAttributeNS(ns, name.toString(), ""); } else { if (!element.hasAttribute(name.getName())) { element.setAttribute(name.getName(), ""); } } NodeIterator it = attributeIterator(name); it.setPosition(1); return it.getNodePointer(); } public void remove() { Node parent = node.getParentNode(); if (parent == null) { throw new JXPathException("Cannot remove root DOM node"); } parent.removeChild(node); } public String asPath() { if (id != null) { return "id('" + escape(id) + "')"; } StringBuffer buffer = new StringBuffer(); if (parent != null) { buffer.append(parent.asPath()); } switch (node.getNodeType()) { case Node.ELEMENT_NODE : // If the parent pointer is not a DOMNodePointer, it is // the parent's responsibility to produce the node test part // of the path if (parent instanceof DOMNodePointer) { if (buffer.length() == 0 || buffer.charAt(buffer.length() - 1) != '/') { buffer.append('/'); } String ln = DOMNodePointer.getLocalName(node); String nsURI = getNamespaceURI(); if (equalStrings(nsURI, getNamespaceResolver().getDefaultNamespaceURI())) { buffer.append(ln); buffer.append('['); buffer.append(get

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS> new JXPathException( "Factory is not set on the JXPathContext - " + "cannot create path: " + asPath()); } return factory; } public int compareChildNodePointers( NodePointer pointer1, NodePointer pointer2) { Node node1 = (Node) pointer1.getBaseValue(); Node node2 = (Node) pointer2.getBaseValue(); if (node1 == node2) { return 0; } int t1 = node1.getNodeType(); int t2 = node2.getNodeType(); if (t1 == Node.ATTRIBUTE_NODE && t2 != Node.ATTRIBUTE_NODE) { return -1; } if (t1 != Node.ATTRIBUTE_NODE && t2 == Node.ATTRIBUTE_NODE) { return 1; } if (t1 == Node.ATTRIBUTE_NODE && t2 == Node.ATTRIBUTE_NODE) { NamedNodeMap map = ((Node) getNode()).getAttributes(); int length = map.getLength(); for (int i = 0; i < length; i++) { Node n = map.item(i); if (n == node1) { return -1; } if (n == node2) { return 1; } } return 0; // Should not happen } Node current = node.getFirstChild(); while (current != null) { if (current == node1) { return -1; } if (current == node2) { return 1; } current = current.getNextSibling(); } return 0; } }

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS> points to a DOM node. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class JDOMNodePointer extends NodePointer { private static final long serialVersionUID = -6346532297491082651L; private Object node; private String id; public static final String XML_NAMESPACE_URI = "http://www.w3.org/XML/1998/namespace"; public static final String XMLNS_NAMESPACE_URI = "http://www.w3.org/2000/xmlns/"; public JDOMNodePointer(Object node, Locale locale) { super(null, locale); this.node = node; } public JDOMNodePointer(Object node, Locale locale, String id) { super(null, locale); this.node = node; this.id = id; } public JDOMNodePointer(NodePointer parent, Object node) { super(parent); this.node = node; } public NodeIterator childIterator( NodeTest test, boolean reverse, NodePointer startWith) { return new JDOMNodeIterator(this, test, reverse, startWith); } public NodeIterator attributeIterator(QName name) { return new JDOMAttributeIterator(this, name); } public NodeIterator namespaceIterator() { return new JDOMNamespaceIterator(this); } public NodePointer namespacePointer(String prefix) { return new JDOMNamespacePointer(this, prefix); } public String getNamespaceURI() { return getNamespaceURI(node); } private static String getNamespaceURI(Object node) { if (node instanceof Element) { Element element = (Element) node; String ns = element.getNamespaceURI(); if (ns != null && ns.equals("")) { ns = null; } return ns; } return null; } public String getNamespaceURI(String prefix) { if (node instanceof Document) { Element element = ((Document)node).getRootElement(); Namespace ns = element.getNamespace(prefix); if (ns != null) { return ns.getURI(); } } else if (node

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS> instanceof Element) { Element element = (Element) node; Namespace ns = element.getNamespace(prefix); if (ns != null) { return ns.getURI(); } } return null; } public int compareChildNodePointers( NodePointer pointer1, NodePointer pointer2) { Object node1 = pointer1.getBaseValue(); Object node2 = pointer2.getBaseValue(); if (node1 == node2) { return 0; } if ((node1 instanceof Attribute) && !(node2 instanceof Attribute)) { return -1; } if ( !(node1 instanceof Attribute) && (node2 instanceof Attribute)) { return 1; } if ( (node1 instanceof Attribute) && (node2 instanceof Attribute)) { List list = ((Element) getNode()).getAttributes(); int length = list.size(); for (int i = 0; i < length; i++) { Object n = list.get(i); if (n == node1) { return -1; } else if (n == node2) { return 1; } } return 0; // Should not happen } if (!(node instanceof Element)) { throw new RuntimeException( "JXPath internal error: " + "compareChildNodes called for " + node); } List children = ((Element) node).getContent(); int length = children.size(); for (int i = 0; i < length; i++) { Object n = children.get(i); if (n == node1) { return -1; } if (n == node2) { return 1; } } return 0; } /** * @see org.apache.commons.jxpath.ri.model.NodePointer#getBaseValue() */ public Object getBaseValue() { return node; } public boolean isCollection() { return false; } public int getLength() { return 1; } public boolean isLeaf() { if (node instanceof Element) { return ((Element) node).getContent().size() == 0; } if (node instanceof Document) { return ((Document) node).getContent().size() ==

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS> child).clone(); element.addContent((Comment) child); } } } public boolean testNode(NodeTest test) { return testNode(this, node, test); } public static boolean testNode( NodePointer pointer, Object node, NodeTest test) { if (test == null) { return true; } if (test instanceof NodeNameTest) { if (!(node instanceof Element)) { return false; } NodeNameTest nodeNameTest = (NodeNameTest) test; QName testName = nodeNameTest.getNodeName(); String namespaceURI = nodeNameTest.getNamespaceURI(); boolean wildcard = nodeNameTest.isWildcard(); String testPrefix = testName.getPrefix(); if (wildcard && testPrefix == null) { return true; } if (wildcard || testName.getName() .equals(JDOMNodePointer.getLocalName(node))) { String nodeNS = JDOMNodePointer.getNamespaceURI(node); return equalStrings(namespaceURI, nodeNS); } return false; } if (test instanceof NodeTypeTest) { switch (((NodeTypeTest) test).getNodeType()) { case Compiler.NODE_TYPE_NODE : return (node instanceof Element) || (node instanceof Document); case Compiler.NODE_TYPE_TEXT : return (node instanceof Text) || (node instanceof CDATA); case Compiler.NODE_TYPE_COMMENT : return node instanceof Comment; case Compiler.NODE_TYPE_PI : return node instanceof ProcessingInstruction; } return false; } if (test instanceof ProcessingInstructionTest && node instanceof ProcessingInstruction) { String testPI = ((ProcessingInstructionTest) test).getTarget(); String nodePI = ((ProcessingInstruction) node).getTarget(); return testPI.equals(nodePI); } return false; } private static boolean equalStrings(String s1, String s2) { if (s1 == s2) { return true; } s1 = s1 == null ? "" : s1.trim(); s2 = s2 == null ? "" : s2.trim(); return s1.equals(s2); } public static String getPrefix(Object node) { if (node instanceof Element) { String prefix =

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS> ((Element) node).getNamespacePrefix(); return (prefix == null || prefix.equals("")) ? null : prefix; } if (node instanceof Attribute) { String prefix = ((Attribute) node).getNamespacePrefix(); return (prefix == null || prefix.equals("")) ? null : prefix; } return null; } public static String getLocalName(Object node) { } if (node instanceof Text) { return (Element) ((Text) node).getParent(); } if (node instanceof CDATA) { return (Element) ((CDATA) node).getParent(); } if (node instanceof ProcessingInstruction) { return (Element) ((ProcessingInstruction) node).getParent(); } if (node instanceof Comment) { return (Element) ((Comment) node).getParent(); } return null; } public NodePointer createChild( JXPathContext context, QName name, int index) { if (index == WHOLE_COLLECTION) { index = 0; } boolean success = getAbstractFactory(context).createObject( context, this, node, name.toString(), index); if (success) { NodeTest nodeTest; String prefix = name.getPrefix(); String namespaceURI = prefix != null ? context.getNamespaceURI(prefix) : context.getDefaultNamespaceURI(); nodeTest = new NodeNameTest(name, namespaceURI); NodeIterator it = childIterator(nodeTest, false, null); if (it != null && it.setPosition(index + 1)) { return it.getNodePointer(); } } throw new JXPathAbstractFactoryException("Factory could not create " + "a child node for path: " + asPath() + "/" + name + "[" + (index + 1) + "]"); } public NodePointer createChild( JXPathContext context, QName name, int index, Object value) { NodePointer ptr = createChild(context, name, index); ptr.setValue(value); return ptr; } public NodePointer createAttribute(JXPathContext context, QName name) { if (!(node instanceof Element)) { return super.createAttribute(context, name); } Element element = (Element) node; String prefix =

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS> name.getPrefix(); if (prefix != null) { Namespace ns = element.getNamespace(prefix); if (ns == null) { throw new JXPathException( "Unknown namespace prefix: " + prefix); } Attribute attr = element.getAttribute(name.getName(), ns); if (attr == null) { element.setAttribute(name.getName(), "", ns); } } else { Attribute attr = element.getAttribute(name.getName()); if (attr == null) { element.setAttribute(name.getName(), ""); } } NodeIterator it = attributeIterator(name); it.setPosition(1); return it.getNodePointer(); } public void remove() { Element parent = nodeParent(node); if (parent == null) { throw new JXPathException("Cannot remove root JDOM node"); } parent.getContent().remove(node); } public String asPath() { if (id != null) { return "id('" + escape(id) + "')"; } StringBuffer buffer = new StringBuffer(); if (parent != null) { buffer.append(parent.asPath()); } if (node instanceof Element) { // If the parent pointer is not a JDOMNodePointer, it is // the parent's responsibility to produce the node test part // of the path if (parent instanceof JDOMNodePointer) { if (buffer.length() == 0 || buffer.charAt(buffer.length() - 1) != '/') { buffer.append('/'); } String nsURI = getNamespaceURI(); String ln = JDOMNodePointer.getLocalName(node); if (equalStrings(nsURI, getNamespaceResolver().getDefaultNamespaceURI())) { buffer.append(ln); buffer.append('['); buffer.append(getRelativePositionByName()).append(']'); } else { String prefix = getNamespaceResolver().getPrefix(nsURI); if (prefix != null) { buffer.append(prefix); buffer.append(':'); buffer.append(ln); buffer.append('['); buffer.append(getRelativePositionByName()); buffer.append(']'); } else { buffer.append("node()"); buffer.append('['); buffer.append(

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>getRelativePositionOfElement()); buffer.append(']'); } } } } else if (node instanceof Text || node instanceof CDATA) { buffer.append("/text()"); buffer.append('[').append(getRelativePositionOfTextNode()).append( ']'); } else if (node instanceof ProcessingInstruction) { String target = ((ProcessingInstruction) node).getTarget(); buffer.append("/processing-instruction(\'").append(target).append( "')"); buffer.append('[').append(getRelativePositionOfPI(target)).append( ']'); } return buffer.toString(); } private String escape(String string) { int index = string.indexOf('\''); while (index != -1) { string = string.substring(0, index) + "&apos;" + string.substring(index + 1); index = string.indexOf('\''); } index = string.indexOf('\"'); while (index != -1) { string = string.substring(0, index) + "&quot;" + string.substring(index + 1); index = string.indexOf('\"'); } return string; } private int getRelativePositionByName() { if (node instanceof Element) { Object parent = ((Element) node).getParent(); if (!(parent instanceof Element)) { return 1; } List children = ((Element)parent).getContent(); int count = 0; String name = ((Element) node).getQualifiedName(); for (int i = 0; i < children.size(); i++) { Object child = children.get(i); if ((child instanceof Element) && ((Element) child).getQualifiedName().equals(name)) { count++; } if (child == node) { break; } } return count; } return 1; } private int getRelativePositionOfElement() { Object parent = ((Element) node).getParent(); if (parent == null) { return 1; } List children; if (parent instanceof Element) { children = ((Element) parent).getContent(); } else { children = ((Document) parent).getContent(); } int count = 0; for (

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>int i = 0; i < children.size(); i++) { Object child = children.get(i); if (child instanceof Element) { count++; } if (child == node) { break; } } return count; } private int getRelativePositionOfTextNode() { Element parent; if (node instanceof Text) { parent = (Element) ((Text) node).getParent(); } else { parent = (Element) ((CDATA) node).getParent(); } if (parent == null) { return 1; } List children = parent.getContent(); int count = 0; for (int i = 0; i < children.size(); i++) { Object child = children.get(i); if (child instanceof Text || child instanceof CDATA) { count++; } if (child == node) { break; } } return count; } private int getRelativePositionOfPI(String target) { Element parent = (Element) ((ProcessingInstruction) node).getParent(); if (parent == null) { return 1; } List children = parent.getContent(); int count = 0; for (int i = 0; i < children.size(); i++) { Object child = children.get(i); if (child instanceof ProcessingInstruction && (target == null || target.equals( ((ProcessingInstruction) child).getTarget()))) { count++; } if (child == node) { break; } } return count; } public int hashCode() { return System.identityHashCode(node); } public boolean equals(Object object) {

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model; import org.apache.commons.jxpath.AbstractFactory; import org.apache.commons.jxpath.JXPathAbstractFactoryException; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.JXPathException; import org.apache.commons.jxpath.JXPathIntrospector; import org.apache.commons.jxpath.JXPathInvalidAccessException; import org.apache.commons.jxpath.Variables; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.compiler.NodeTest; import org.apache.commons.jxpath.ri.model.beans.NullPointer; import org.apache.commons.jxpath.util.ValueUtils; /** * Pointer to a context variable. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class VariablePointer extends NodePointer { private Variables variables; private QName name; private NodePointer valuePointer; private boolean actual; public VariablePointer(Variables variables, QName name) { super(null); this.variables = variables; this.name = name; actual = true; } public VariablePointer(QName name) { super(null); this.name = name; actual = false; } public boolean isContainer()

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS> { return true; } public QName getName() { return name; } public Object getBaseValue() { if (!actual) { throw new JXPathException("Undefined variable: " + name); } return variables.getVariable(name.toString()); } public boolean isLeaf() { Object value = getNode(); return value == null || JXPathIntrospector.getBeanInfo(value.getClass()).isAtomic(); } public boolean isCollection() { Object value = getBaseValue(); return value != null && ValueUtils.isCollection(value); } public Object getImmediateNode() { Object value = getBaseValue(); return index == WHOLE_COLLECTION ? ValueUtils.getValue(value) : ValueUtils.getValue(value, index); } public void setValue(Object value) { if (!actual) { throw new JXPathException("Cannot set undefined variable: " + name); } valuePointer = null; if (index != WHOLE_COLLECTION) { Object collection = getBaseValue(); ValueUtils.setValue(collection, index, value); } else { variables.declareVariable(name.toString(), value); } } public boolean isActual() { return actual; } public void setIndex(int index) { super.setIndex(index); valuePointer = null; } public NodePointer getImmediateValuePointer() { if (valuePointer == null) { Object value = null; if (actual) { value = getImmediateNode(); valuePointer = NodePointer.newChildNodePointer(this, null, value); } else { return new NullPointer(this, getName()) { public Object getImmediateNode() { throw new JXPathException( "Undefined variable: " + name); } }; } } return valuePointer; } public int getLength() { if (actual) { Object value = getBaseValue(); return value == null ? 1 : ValueUtils.getLength(value); } return 0; } public NodePointer createPath(JXPathContext context, Object value) { if (actual) { setValue(value); return this; } NodePointer ptr = createPath(context);

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS> ptr.setValue(value); return ptr; } public NodePointer createPath(JXPathContext context) { if (!actual) { AbstractFactory factory = getAbstractFactory(context); if (!factory.declareVariable(context, name.toString())) { throw new JXPathAbstractFactoryException( "Factory cannot define variable '" + name + "' for path: " + asPath()); } findVariables(context); // Assert: actual == true } return this; } public NodePointer createChild( JXPathContext context, QName name, int index) { Object collection = createCollection(context, index); if (!isActual() || (index != 0 && index != WHOLE_COLLECTION)) { AbstractFactory factory = getAbstractFactory(context); boolean success = factory.createObject( context, this, collection, getName().toString(), index); if (!success) { throw new JXPathAbstractFactoryException( "Factory could not create object path: " + asPath()); } NodePointer cln = (NodePointer) clone(); cln.setIndex(index); return cln; } return this; } public NodePointer createChild( JXPathContext context, QName name, int index, Object value) { Object collection = createCollection(context, index); ValueUtils.setValue(collection, index, value); NodePointer cl = (NodePointer) clone(); cl.setIndex(index); return cl; } private Object createCollection(JXPathContext context, int index) { createPath(context); Object collection = getBaseValue(); if (collection == null) { throw new JXPathAbstractFactoryException( "Factory did not assign a collection to variable '" + name + "' for path: " + asPath()); } if (index == WHOLE_COLLECTION) { index = 0; } else if (index < 0) { throw new JXPathInvalidAccessException("Index is less than 1: " + asPath()); } if (index >= getLength()) { collection = ValueUtils.expandCollection(collection, index + 1); variables.declareVariable(name.toString(), collection); }

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS> return collection; } public void remove() { if (actual) { if (index == WHOLE_COLLECTION) { variables.undeclareVariable(name.toString()); } else { if (index < 0) { throw new JXPathInvalidAccessException( "Index is less than 1: " + asPath()); } Object collection = getBaseValue(); if (collection != null && index < getLength()) { collection = ValueUtils.remove(collection, index); variables.declareVariable(name.toString(), collection); } } } } protected void findVariables(JXPathContext context) { valuePointer = null; JXPathContext varCtx = context; while (varCtx != null) { variables = varCtx.getVariables(); if (variables.isDeclaredVariable(name.toString())) { actual = true; break; } varCtx = varCtx.getParentContext(); variables = null; } } public int hashCode() { return (actual ? System.identityHashCode(variables) : 0) + name.hashCode() + index; } public boolean equals(Object object) { if (object == this) { return true; } if (!(object instanceof VariablePointer)) { return false; } VariablePointer other = (VariablePointer) object; return variables == other.variables && name.equals(other.name) && index == other.index; } public String asPath() { StringBuffer buffer = new StringBuffer(); buffer.append('$'); buffer.append(name); if (!actual) { if (index != WHOLE_COLLECTION) { buffer.append('[').append(index + 1).append(']'); } } else if ( index != WHOLE_COLLECTION && (getNode() == null || isCollection())) { buffer.append('[').append(index + 1).append(']'); } return buffer.toString(); } public NodeIterator childIterator( NodeTest test, boolean reverse, NodePointer startWith) { return getValuePointer().childIterator(test, reverse, startWith); } public NodeIterator attributeIterator(QName name) { return getValuePointer().attributeIterator(name);

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS> } public NodeIterator namespaceIterator() { return getValuePointer().namespaceIterator(); } public NodePointer namespacePointer(String name) { return getValuePointer().namespacePointer(name); } public boolean testNode(NodeTest nodeTest) { return getValuePointer().testNode(nodeTest); } private AbstractFactory getAbstractFactory(JXPathContext context) { AbstractFactory factory = context.getFactory(); if (factory == null) { throw new JXPathException( "Factory is not set on the JXPathContext - cannot create path: " + asPath()); } return factory; } public int compareChildNodePointers( NodePointer pointer1, NodePointer pointer2) { return pointer1.getIndex() - pointer2.getIndex(); } }

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri; import java.io.StringReader; import org.apache.commons.jxpath.JXPathInvalidSyntaxException; import org.apache.commons.jxpath.ri.parser.ParseException; import org.apache.commons.jxpath.ri.parser.TokenMgrError; import org.apache.commons.jxpath.ri.parser.XPathParser; /** * XPath parser * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class Parser { private static XPathParser parser = new XPathParser(new StringReader("")); /** * Parses the XPath expression. Throws a JXPathException in case * of a syntax error. */ public static Object parseExpression( String expression, Compiler compiler) { synchronized (parser) { parser.setCompiler(compiler); Object expr = null; try { parser.ReInit(new StringReader(expression)); expr = parser.parseExpression(); } catch (TokenMgrError e) { throw new JXPathInvalidSyntaxException( "Invalid XPath: '" + addEscapes(expression) + "'. Invalid symbol '" + addEscapes(String.valueOf(e.getCharacter())) + "' " + describePosition(expression, e.getPosition())); } catch (ParseException e) { throw new JXPathInvalidSyntaxException( "Invalid XPath: '" + addEsc

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.dynabeans; import java.util.Locale; import org.apache.commons.beanutils.DynaBean; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.model.NodePointer; import org.apache.commons.jxpath.ri.model.NodePointerFactory; /** * Implements NodePointerFactory for DynaBeans. * See <a href="http://jakarta.apache.org/commons/beanutils.html"> * Jakarta Commons BeanUtils * </a> * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class DynaBeanPointerFactory implements NodePointerFactory { public static final int DYNA_BEAN_POINTER_FACTORY_ORDER = 700; public int getOrder() { return DYNA_BEAN_POINTER_FACTORY_ORDER; } public NodePointer createNodePointer( QName name, Object bean, Locale locale) { return bean instanceof DynaBean ? new DynaBeanPointer(name, (DynaBean) bean, locale) : null; } public NodePointer createNodePointer( NodePointer parent, QName name, Object bean) { return bean instanceof DynaBean ? new DynaBeanPointer(parent, name, (DynaBean) bean) : null; }

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.jdom; import java.util.ArrayList; import java.util.Collections; import java.util.List; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.model.NodeIterator; import org.apache.commons.jxpath.ri.model.NodePointer; import org.jdom.Attribute; import org.jdom.Element; import org.jdom.Namespace; /** * An iterator of attributes of a DOM Node. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class JDOMAttributeIterator implements NodeIterator { private NodePointer parent; private List attributes; private int position = 0; public JDOMAttributeIterator(NodePointer parent, QName name) { this.parent = parent; if (parent.getNode() instanceof Element) { Element element = (Element) parent.getNode(); String prefix = name.getPrefix(); Namespace ns; if (prefix != null) { if (prefix.equals("xml")) { ns = Namespace.XML_NAMESPACE; } else { ns = element.getNamespace(prefix); if (ns == null) { // TBD: no attributes attributes = Collections.EMPTY_LIST; return; } } } else { ns = Namespace.NO

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>_NAMESPACE; } String lname = name.getName(); if (!lname.equals("*")) { attributes = new ArrayList(); if (ns != null) { Attribute attr = element.getAttribute(lname, ns); if (attr != null) { attributes.add(attr); } } } else { attributes = new ArrayList(); List allAttributes = element.getAttributes(); for (int i = 0; i < allAttributes.size(); i++) { Attribute attr = (Attribute) allAttributes.get(i); if (attr.getNamespace().equals(ns)) { attributes.add(attr); } } } } } public NodePointer getNodePointer() { if (position == 0) { if (!setPosition(1)) { return null; } position = 0; } int index = position - 1; if (index < 0) { index = 0; } return new JDOMAttributePointer( parent, (Attribute) attributes.get(index)); } public int getPosition() { return position; } public boolean setPosition(int position) { if (attributes == null) { return false; } this.position = position; return position >= 1 && position <= attributes.size(); } }

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model; import java.util.Locale; import org.apache.commons.jxpath.ri.QName; /** * Creates NodePointers for objects of a certain type. * NodePointerFactories are ordered according to the values returned * by the "getOrder" method and always queried in that order. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public interface NodePointerFactory { /** * The factory order number determines its position between other factories. */ int getOrder(); /** * Create a NodePointer for the supplied object. The node will represent * the "root" object for a path. * * @return null if this factory does not recognize objects of the supplied * type. */ NodePointer createNodePointer(QName name, Object object, Locale locale); /** * Create a NodePointer for the supplied child object. * <p> * @return null if this factory does not recognize objects of the supplied * type. */ NodePointer createNodePointer( NodePointer parent, QName name, Object object); }

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.dom; import java.util.Locale; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.model.NodePointer; import org.apache.commons.jxpath.ri.model.NodePointerFactory; import org.w3c.dom.Node; /** * Implements NodePointerFactory for DOM elements. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class DOMPointerFactory implements NodePointerFactory { public static final int DOM_POINTER_FACTORY_ORDER = 100; public int getOrder() { return DOM_POINTER_FACTORY_ORDER; } public NodePointer createNodePointer( QName name, Object bean, Locale locale) { return bean instanceof Node ? new DOMNodePointer((Node) bean, locale) : null; } public NodePointer createNodePointer( NodePointer parent, QName name, Object bean) { return bean instanceof Node ? new DOMNodePointer(parent, (Node) bean) : null; } }

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.axes; import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.compiler.NodeNameTest; import org.apache.commons.jxpath.ri.compiler.NodeTest; import org.apache.commons.jxpath.ri.model.NodeIterator; import org.apache.commons.jxpath.ri.model.NodePointer; /** * EvalContext that walks the "namespace::" axis. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class NamespaceContext extends EvalContext { private NodeTest nodeTest; private boolean setStarted = false; private NodeIterator iterator; private NodePointer currentNodePointer; /** * @param parentContext represents the previous step on the path * @param nodeTest is the name of the namespace we are looking for */ public NamespaceContext(EvalContext parentContext, NodeTest nodeTest) { super(parentContext); this.nodeTest = nodeTest; } public NodePointer getCurrentNodePointer() { return currentNodePointer; } public void reset() { setStarted = false; iterator = null; super.reset(); } public boolean setPosition(int position) { if (position < getCurrentPosition()) { reset(); } while (

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>getCurrentPosition() < position) { if (!nextNode()) { return false; } } return true; } public boolean nextNode() { super.setPosition(getCurrentPosition() + 1); if (!setStarted) { setStarted = true; if (!(nodeTest instanceof NodeNameTest)) { return false; } NodeNameTest nodeNameTest = (NodeNameTest) nodeTest; QName testName = nodeNameTest.getNodeName(); if (testName.getPrefix() != null) { return false; } if (nodeNameTest.isWildcard()) { iterator = parentContext.getCurrentNodePointer().namespaceIterator(); } else { currentNodePointer = parentContext.getCurrentNodePointer().namespacePointer( testName.getName()); return currentNodePointer != null; } } if (iterator == null) { return false; } if (!iterator.setPosition(iterator.getPosition() + 1)) { return false; } currentNodePointer = iterator.getNodePointer(); return true; } }

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.axes; import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.compiler.NodeTest; import org.apache.commons.jxpath.ri.model.NodePointer; /** * EvalContext that walks the "ancestor::" and "ancestor-or-self::" axes. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class AncestorContext extends EvalContext { private NodeTest nodeTest; private boolean setStarted = false; private NodePointer currentNodePointer; private boolean includeSelf; /** * @param parentContext represents the previous step on the path * @param includeSelf differentiates between "ancestor::" and "ancestor- * or-self::" axes * @param nameTest is the name of the element(s) we are looking for */ public AncestorContext( EvalContext parentContext, boolean includeSelf, NodeTest nodeTest) { super(parentContext); this.includeSelf = includeSelf; this.nodeTest = nodeTest; } public NodePointer getCurrentNodePointer() { return currentNodePointer; } public int getDocumentOrder() { return -1; } public void reset() { super.reset(); setStarted = false; } public boolean setPosition(int position) {

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.dom; import org.apache.commons.jxpath.ri.compiler.NodeTest; import org.apache.commons.jxpath.ri.model.NodeIterator; import org.apache.commons.jxpath.ri.model.NodePointer; import org.w3c.dom.Node; /** * An iterator of children of a DOM Node. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class DOMNodeIterator implements NodeIterator { private NodePointer parent; private NodeTest nodeTest; private Node node; private Node child = null; private boolean reverse; private int position = 0; public DOMNodeIterator( NodePointer parent, NodeTest nodeTest, boolean reverse, NodePointer startWith) { this.parent = parent; this.node = (Node) parent.getNode(); if (startWith != null) { this.child = (Node) startWith.getNode(); } this.nodeTest = nodeTest; this.reverse = reverse; } public NodePointer getNodePointer() { if (position == 0) { setPosition(1); } return child == null ? null : new DOMNodePointer(parent, child); } public int getPosition() { return position; } public boolean setPosition(int position) { while (

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.axes; import java.util.Stack; import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.compiler.NodeTest; import org.apache.commons.jxpath.ri.model.NodeIterator; import org.apache.commons.jxpath.ri.model.NodePointer; import org.apache.commons.jxpath.ri.model.beans.PropertyIterator; /** * EvalContext that walks the "preceding::" and "following::" axes. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class PrecedingOrFollowingContext extends EvalContext { private NodeTest nodeTest; private boolean setStarted = false; private Stack stack; private NodePointer currentNodePointer; private NodePointer currentRootLocation; private boolean reverse; public PrecedingOrFollowingContext( EvalContext parentContext, NodeTest nodeTest, boolean reverse) { super(parentContext); this.nodeTest = nodeTest; this.reverse = reverse; } public NodePointer getCurrentNodePointer() { return currentNodePointer; } public int getDocumentOrder() { return reverse ? -1 : 1; } public void reset() { super.reset(); stack = new Stack(); setStarted = false; } public boolean

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS> setPosition(int position) { if (position < this.position) { reset(); } while (this.position < position) { if (!nextNode()) { return false; } } return true; } public boolean nextNode() { if (!setStarted) { setStarted = true; currentRootLocation = parentContext.getCurrentNodePointer(); NodePointer parent = currentRootLocation.getParent(); if (parent != null) { // TBD: check type stack.push( parent.childIterator(null, reverse, currentRootLocation)); } } while (true) { if (stack.isEmpty()) { currentRootLocation = currentRootLocation.getParent(); if (currentRootLocation == null || currentRootLocation.isRoot()) { break; } NodePointer parent = currentRootLocation.getParent(); if (parent != null) { stack.push( parent.childIterator( null, reverse, currentRootLocation)); } } while (!stack.isEmpty()) { if (!reverse) { NodeIterator it = (NodeIterator) stack.peek(); if (it.setPosition(it.getPosition() + 1)) { currentNodePointer = it.getNodePointer(); if (!currentNodePointer.isLeaf()) { stack.push( currentNodePointer.childIterator( null, reverse, null)); } if (currentNodePointer.testNode(nodeTest)) { super.setPosition(getCurrentPosition() + 1); return true; } } else { // We get here only if the name test failed // and the iterator ended stack.pop(); } } else { NodeIterator it = (NodeIterator) stack.peek(); if (it.setPosition(it.getPosition() + 1)) { currentNodePointer = it.getNodePointer(); if (!currentNodePointer.isLeaf()) { stack.push( currentNodePointer.childIterator( null, reverse, null)); } else if (currentNodePointer.testNode(nodeTest)) { super.setPosition(getCurrentPosition() + 1); return true; } } else { stack.pop(); if (!stack.isEmpty()) { it = (PropertyIterator) stack.peek();

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS> currentNodePointer = it.getNodePointer(); if (currentNodePointer.testNode(nodeTest)) { super.setPosition(getCurrentPosition() + 1); return true; } } } } } } return false; } }

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.beans; import java.util.Locale; import org.apache.commons.jxpath.JXPathInvalidAccessException; import org.apache.commons.jxpath.ri.Compiler; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.compiler.NodeNameTest; import org.apache.commons.jxpath.ri.compiler.NodeTest; import org.apache.commons.jxpath.ri.compiler.NodeTypeTest; import org.apache.commons.jxpath.ri.model.NodeIterator; import org.apache.commons.jxpath.ri.model.NodePointer; import org.apache.commons.jxpath.util.ValueUtils; /** * A pointer describing a node that has properties, each of which could be * a collection. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public abstract class PropertyOwnerPointer extends NodePointer { public NodeIterator childIterator( NodeTest test, boolean reverse, NodePointer startWith) { if (test == null) { return createNodeIterator(null, reverse, startWith); } if (test instanceof NodeNameTest) { NodeNameTest nodeNameTest = (NodeNameTest) test; QName testName = nodeNameTest.getNodeName(); if (!isDefaultNamespace(testName.getPrefix

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>())) { return null; } String property = nodeNameTest.isWildcard() ? null : testName.getName(); return createNodeIterator(property, reverse, startWith); } return test instanceof NodeTypeTest && ((NodeTypeTest) test).getNodeType() == Compiler.NODE_TYPE_NODE ? createNodeIterator(null, reverse, startWith) : null; } public NodeIterator createNodeIterator( String property, boolean reverse, NodePointer startWith) { return new PropertyIterator(this, property, reverse, startWith); } public NodeIterator attributeIterator(QName name) { return new BeanAttributeIterator(this, name); } protected PropertyOwnerPointer(NodePointer parent, Locale locale) { super(parent, locale); } protected PropertyOwnerPointer(NodePointer parent) { super(parent); } public void setIndex(int index) { if (this.index != index) { super.setIndex(index); value = UNINITIALIZED; } } private static final Object UNINITIALIZED = new Object(); private Object value = UNINITIALIZED; public Object getImmediateNode() { if (value == UNINITIALIZED) { value = index == WHOLE_COLLECTION ? ValueUtils.getValue(getBaseValue()) : ValueUtils.getValue(getBaseValue(), index); } return value; } public abstract QName getName(); /** * Throws an exception if you try to change the root element, otherwise * forwards the call to the parent pointer. */ public void setValue(Object value) { this.value = value; if (parent.isContainer()) { parent.setValue(value); } else if (parent != null) { if (index == WHOLE_COLLECTION) { throw new UnsupportedOperationException( "Cannot setValue of an object that is not " + "some other object's property"); } throw new JXPathInvalidAccessException( "The specified collection element does not exist: " + this); } else { throw new UnsupportedOperationException( "Cannot replace the root object"); } } /** * If this is a root node pointer, throws an exception; otherwise * forwards the call to the parent node. */ public void remove() { this.value = null

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>; if (parent != null) { parent.remove(); } else { throw new UnsupportedOperationException( "Cannot remove an object that is not " + "some other object's property or a collection element"); } } public abstract PropertyPointer getPropertyPointer(); /** * @return true if the property owner can set a property "does not exist". * A good example is a Map. You can always assign a value to any * key even if it has never been "declared". */ public boolean isDynamicPropertyDeclarationSupported() { return false; } public int compareChildNodePointers( NodePointer pointer1, NodePointer pointer2) { int r = pointer1.getName().toString().compareTo(pointer2.getName().toString()); return r == 0 ? pointer1.getIndex() - pointer2.getIndex() : r; } }

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>Column, errorAfter, curChar), reason); // ADDED BY ME FROM THIS POINT TO THE EOF - DMITRI PLOTNIKOV position = errorColumn - 1; character = curChar; } private int position; private char character; public int getPosition(){ return position; } public char getCharacter(){ return character; } }

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.dynabeans; import java.util.Locale; import org.apache.commons.beanutils.DynaBean; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.model.NodePointer; import org.apache.commons.jxpath.ri.model.beans.PropertyOwnerPointer; import org.apache.commons.jxpath.ri.model.beans.PropertyPointer; /** * A Pointer that points to a DynaBean. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class DynaBeanPointer extends PropertyOwnerPointer { private QName name; private DynaBean dynaBean; public DynaBeanPointer(QName name, DynaBean dynaBean, Locale locale) { super(null, locale); this.name = name; this.dynaBean = dynaBean; } /** * @param name is the name given to the first node */ public DynaBeanPointer(NodePointer parent, QName name, DynaBean dynaBean) { super(parent); this.name = name; this.dynaBean = dynaBean; } public PropertyPointer getPropertyPointer() { return new DynaBeanPropertyPointer(this, dynaBean); } public QName getName() { return name;

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.axes; import java.util.Stack; import org.apache.commons.jxpath.Pointer; import org.apache.commons.jxpath.ri.Compiler; import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.compiler.NodeTest; import org.apache.commons.jxpath.ri.compiler.NodeTypeTest; import org.apache.commons.jxpath.ri.model.NodeIterator; import org.apache.commons.jxpath.ri.model.NodePointer; /** * An EvalContext that walks the "descendant::" and "descendant-or-self::" * axes. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class DescendantContext extends EvalContext { private NodeTest nodeTest; private boolean setStarted = false; private Stack stack; private NodePointer currentNodePointer; private boolean includeSelf; private static final NodeTest ELEMENT_NODE_TEST = new NodeTypeTest(Compiler.NODE_TYPE_NODE); public DescendantContext( EvalContext parentContext, boolean includeSelf, NodeTest nodeTest) { super(parentContext); this.includeSelf = includeSelf; this.nodeTest = nodeTest; } public boolean isChildOrderingRequired() { return true; }

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS> public NodePointer getCurrentNodePointer() { if (position == 0) { if (!setPosition(1)) { return null; } } return currentNodePointer; } public void reset() { super.reset(); setStarted = false; } public boolean setPosition(int position) { if (position < this.position) { reset(); } while (this.position < position) { if (!nextNode()) { return false; } } return true; } public boolean nextNode() { if (!setStarted) { setStarted = true; stack = new Stack(); currentNodePointer = parentContext.getCurrentNodePointer(); if (currentNodePointer != null) { if (!currentNodePointer.isLeaf()) { stack.push( currentNodePointer.childIterator( ELEMENT_NODE_TEST, false, null)); } if (includeSelf) { if (currentNodePointer.testNode(nodeTest)) { position++; return true; } } } } while (!stack.isEmpty()) { NodeIterator it = (NodeIterator) stack.peek(); if (it.setPosition(it.getPosition() + 1)) { currentNodePointer = it.getNodePointer(); if (!isRecursive()) { if (!currentNodePointer.isLeaf()) { stack.push( currentNodePointer.childIterator( ELEMENT_NODE_TEST, false, null)); } if (currentNodePointer.testNode(nodeTest)) { position++; return true; } } } else { // We get here only if the name test failed // and the iterator ended stack.pop(); } } return false; } /** * Checks if we are reentering a bean we have already seen and if so * returns true to prevent infinite recursion. */ private boolean isRecursive() { Object node = currentNodePointer.getNode(); for (int i = stack.size() - 1; --i >= 0;) { NodeIterator it = (NodeIterator) stack.get(i); Pointer pointer = it.getNodePointer(); if (pointer != null && pointer.getNode() == node) { return true; } } return false; } }

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.axes; import org.apache.commons.jxpath.Pointer; import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.compiler.NodeTest; import org.apache.commons.jxpath.ri.model.NodeIterator; import org.apache.commons.jxpath.ri.model.NodePointer; /** * EvalContext that can walk the "child::", "following-sibling::" and * "preceding-sibling::" axes. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class ChildContext extends EvalContext { private NodeTest nodeTest; private boolean startFromParentLocation; private boolean reverse; private NodeIterator iterator; public ChildContext( EvalContext parentContext, NodeTest nodeTest, boolean startFromParentLocation, boolean reverse) { super(parentContext); this.nodeTest = nodeTest; this.startFromParentLocation = startFromParentLocation; this.reverse = reverse; } public NodePointer getCurrentNodePointer() { if (position == 0) { if (!setPosition(1)) { return null; } } return iterator == null ? null : iterator.getNodePointer(); } /** * This method is called on the last context on the path when only * one value is

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS> needed. Note that this will return the whole property, * even if it is a collection. It will not extract the first element * of the collection. For example, "books" will return the collection * of books rather than the first book from that collection. */ public Pointer getSingleNodePointer() { if (position == 0) { while (nextSet()) { prepare(); if (iterator == null) { return null; } // See if there is a property there, singular or collection NodePointer pointer = iterator.getNodePointer(); if (pointer != null) { return pointer; } } return null; } return getCurrentNodePointer(); } public boolean nextNode() { return setPosition(getCurrentPosition() + 1); } public void reset() { super.reset(); iterator = null; } public boolean setPosition(int position) { int oldPosition = getCurrentPosition(); super.setPosition(position); if (oldPosition == 0) { prepare(); } return iterator == null ? false : iterator.setPosition(position); } /** * Allocates a PropertyIterator. */ private void prepare() { NodePointer parent = parentContext.getCurrentNodePointer(); if (parent == null) { return; } iterator = (startFromParentLocation ? parent.getParent() : parent).childIterator(nodeTest, reverse, startFromParentLocation ? parent : null); } }

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.beans; import java.util.Locale; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.model.NodePointer; import org.apache.commons.jxpath.ri.model.NodePointerFactory; import org.apache.commons.jxpath.util.ValueUtils; /** * Implements NodePointerFactory for stand-alone collections. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CollectionPointerFactory implements NodePointerFactory { public static final int COLLECTION_POINTER_FACTORY_ORDER = 10; public int getOrder() { return COLLECTION_POINTER_FACTORY_ORDER; } public NodePointer createNodePointer( QName name, Object bean, Locale locale) { return ValueUtils.isCollection(bean) ? new CollectionPointer(bean, locale) : null; } public NodePointer createNodePointer( NodePointer parent, QName name, Object bean) { return ValueUtils.isCollection(bean) ? new CollectionPointer(parent, bean) : null; } }

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.dom; import org.apache.commons.jxpath.ri.Compiler; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.compiler.NodeTest; import org.apache.commons.jxpath.ri.compiler.NodeTypeTest; import org.apache.commons.jxpath.ri.model.NodePointer; /** * Represents a namespace node. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class NamespacePointer extends NodePointer { private String prefix; private String namespaceURI; public NamespacePointer(NodePointer parent, String prefix) { super(parent); this.prefix = prefix; } public NamespacePointer( NodePointer parent, String prefix, String namespaceURI) { super(parent); this.prefix = prefix; this.namespaceURI = namespaceURI; } public QName getName() { return new QName(prefix); } public Object getBaseValue() { return null; } public boolean isCollection() { return false; } public int getLength() { return 1; } public Object getImmediateNode() { return getNamespaceURI(); } public String getNamespaceURI() { if (namespaceURI == null) { namespaceURI = parent.getNamespaceURI(prefix); }

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS> return namespaceURI; } public boolean isLeaf() { return true; } /** * Throws UnsupportedOperationException. */ public void setValue(Object value) { throw new UnsupportedOperationException("Cannot modify DOM trees"); } public boolean testNode(NodeTest nodeTest) { return nodeTest == null || ((nodeTest instanceof NodeTypeTest) && ((NodeTypeTest) nodeTest).getNodeType() == Compiler.NODE_TYPE_NODE); } public String asPath() { StringBuffer buffer = new StringBuffer(); if (parent != null) { buffer.append(parent.asPath()); if (buffer.length() == 0 || buffer.charAt(buffer.length() - 1) != '/') { buffer.append('/'); } } buffer.append("namespace::"); buffer.append(prefix); return buffer.toString(); } public int hashCode() { return prefix.hashCode(); } public boolean equals(Object object) { if (object == this) { return true; } if (!(object instanceof NamespacePointer)) { return false; } NamespacePointer other = (NamespacePointer) object; return prefix.equals(other.prefix); } public int compareChildNodePointers( NodePointer pointer1, NodePointer pointer2) { // Won't happen - namespaces don't have children return 0; } }

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>DependencyKnown) { contextDependent = computeContextDependent(); contextDependencyKnown = true; } return contextDependent; } /** * Implemented by subclasses and result is cached by isContextDependent() */ public abstract boolean computeContextDependent(); /** * Evaluates the expression. If the result is a node set, returns * the first element of the node set. */ public abstract Object computeValue(EvalContext context); public abstract Object compute(EvalContext context); public Iterator iterate(EvalContext context) { Object result = compute(context); if (result instanceof EvalContext) { return new ValueIterator((EvalContext) result); } if (result instanceof NodeSet) { return new ValueIterator(((NodeSet) result).getPointers().iterator()); } return ValueUtils.iterate(result); } public Iterator iteratePointers(EvalContext context) { Object result = compute(context); if (result == null) { return Collections.EMPTY_LIST.iterator(); } if (result instanceof EvalContext) { return (EvalContext) result; } if (result instanceof NodeSet) { return new PointerIterator(((NodeSet) result).getPointers().iterator(), new QName(null, "value"), context.getRootContext().getCurrentNodePointer().getLocale()); } return new PointerIterator(ValueUtils.iterate(result), new QName(null, "value"), context.getRootContext().getCurrentNodePointer().getLocale()); } public static class PointerIterator implements Iterator { private Iterator iterator; private QName qname; private Locale locale; //to what method does the following comment refer? /** * @deprecated Use the method that takes a NamespaceManager */ public PointerIterator(Iterator it, QName qname, Locale locale) { this.iterator = it; this.qname = qname; this.locale = locale; } public boolean hasNext() { return iterator.hasNext(); } public Object next() { Object o = iterator.next(); return o instanceof Pointer ? o : NodePointer.newNodePointer(qname, o, locale); } public void remove() { throw new UnsupportedOperationException(); } } public static class ValueIterator implements Iterator { private Iterator iterator; public ValueIterator(Iterator it) {

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.axes; import java.util.HashSet; import org.apache.commons.jxpath.BasicNodeSet; import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.model.NodePointer; /** * EvalContext that represents a union between other contexts - result * of a union operation like (a | b) * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class UnionContext extends NodeSetContext { private EvalContext contexts[]; private boolean prepared; public UnionContext(EvalContext parentContext, EvalContext contexts[]) { super(parentContext, new BasicNodeSet()); this.contexts = contexts; } public int getDocumentOrder() { return contexts.length > 1 ? 1 : super.getDocumentOrder(); } public boolean setPosition(int position) { if (!prepared) { prepared = true; BasicNodeSet nodeSet = (BasicNodeSet) getNodeSet(); HashSet set = new HashSet(); for (int i = 0; i < contexts.length; i++) { EvalContext ctx = (EvalContext) contexts[i]; while (ctx.nextSet()) { while (ctx.nextNode()) { NodePointer ptr = ctx.getCurrentNodePointer(); if (!set.contains(ptr)) { nodeSet.add(ptr);

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS> set.add(ptr); } } } } } return super.setPosition(position); } }

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.axes; import org.apache.commons.jxpath.Function; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.NodeSet; import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.JXPathContextReferenceImpl; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.model.NodePointer; /** * EvalContext that is used to hold the root node for the path traversal. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class RootContext extends EvalContext { private JXPathContextReferenceImpl jxpathContext; private NodePointer pointer; private Object registers[]; private int availableRegister = 0; public static final Object UNKNOWN_VALUE = new Object(); private static final int MAX_REGISTER = 4; public RootContext( JXPathContextReferenceImpl jxpathContext, NodePointer pointer) { super(null); this.jxpathContext = jxpathContext; this.pointer = pointer; if (pointer != null) { pointer.setNamespaceResolver(jxpathContext.getNamespaceResolver()); } } public JXPathContext getJXPathContext() { return jxpathContext; } public RootContext get

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>RootContext() { return this; } public EvalContext getAbsoluteRootContext() { return jxpathContext.getAbsoluteRootContext(); } public NodePointer getCurrentNodePointer() { return pointer; } public Object getValue() { return pointer; } public int getCurrentPosition() { throw new UnsupportedOperationException(); } public boolean nextNode() { throw new UnsupportedOperationException(); } public boolean nextSet() { throw new UnsupportedOperationException(); } public boolean setPosition(int position) { throw new UnsupportedOperationException(); } public EvalContext getConstantContext(Object constant) { if (constant instanceof NodeSet) { return new NodeSetContext( new RootContext(jxpathContext, null), (NodeSet) constant); } NodePointer pointer; if (constant instanceof NodePointer) { pointer = (NodePointer) constant; } else { pointer = NodePointer.newNodePointer( new QName(null, ""), constant, null); } return new InitialContext(new RootContext(jxpathContext, pointer)); } public EvalContext getVariableContext(QName variableName) { return new InitialContext( new RootContext( jxpathContext, jxpathContext.getVariablePointer(variableName))); } public Function getFunction(QName functionName, Object[] parameters) { return jxpathContext.getFunction(functionName, parameters); } public Object getRegisteredValue(int id) { if (registers == null || id >= MAX_REGISTER || id == -1) { return UNKNOWN_VALUE; } return registers[id]; } public int setRegisteredValue(Object value) { if (registers == null) { registers = new Object[MAX_REGISTER]; for (int i = 0; i < MAX_REGISTER; i++) { registers[i] = UNKNOWN_VALUE; } } if (availableRegister >= MAX_REGISTER) { return -1; } registers[availableRegister] = value; availableRegister++; return availableRegister - 1; } public String toString() { return super.toString() + ":" + pointer.asPath(); } }

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.jdom; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.model.NodePointer; import org.apache.commons.jxpath.util.TypeUtils; import org.jdom.Attribute; /** * A Pointer that points to a DOM node. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class JDOMAttributePointer extends NodePointer { private Attribute attr; public JDOMAttributePointer(NodePointer parent, Attribute attr) { super(parent); this.attr = attr; } public QName getName() { return new QName( JDOMNodePointer.getPrefix(attr), JDOMNodePointer.getLocalName(attr)); } public String getNamespaceURI() { String uri = attr.getNamespaceURI(); if (uri != null && uri.equals("")) { uri = null; } return uri; } public Object getValue() { return attr.getValue(); } public Object getBaseValue() { return attr; } public boolean isCollection() { return false; } public int getLength() { return 1; } public Object getImmediateNode() { return attr; } public boolean isActual() { return true; } public boolean isLeaf() { return true

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>; } /** * Sets the value of this attribute. */ public void setValue(Object value) { attr.setValue((String) TypeUtils.convert(value, String.class)); } public void remove() { attr.getParent().removeAttribute(attr); } /** */ public String asPath() { StringBuffer buffer = new StringBuffer(); if (parent != null) { buffer.append(parent.asPath()); if (buffer.length() == 0 || buffer.charAt(buffer.length() - 1) != '/') { buffer.append('/'); } } buffer.append('@'); buffer.append(getName()); return buffer.toString(); } public int hashCode() { return System.identityHashCode(attr); } public boolean equals(Object object) { return object == this || object instanceof JDOMAttributePointer && ((JDOMAttributePointer) object).attr == attr; } public int compareChildNodePointers( NodePointer pointer1, NodePointer pointer2) { // Won't happen - attributes don't have children return 0; } }

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.dom; import org.apache.commons.jxpath.ri.Compiler; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.compiler.NodeTest; import org.apache.commons.jxpath.ri.compiler.NodeTypeTest; import org.apache.commons.jxpath.ri.model.NodePointer; import org.apache.commons.jxpath.util.TypeUtils; import org.w3c.dom.Attr; /** * A Pointer that points to a DOM node. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class DOMAttributePointer extends NodePointer { private Attr attr; public DOMAttributePointer(NodePointer parent, Attr attr) { super(parent); this.attr = attr; } public QName getName() { return new QName( DOMNodePointer.getPrefix(attr), DOMNodePointer.getLocalName(attr)); } public String getNamespaceURI() { String prefix = DOMNodePointer.getPrefix(attr); return prefix == null ? null : parent.getNamespaceURI(prefix); } public Object getValue() { String value = attr.getValue(); if (value == null || (value.equals("") && !attr.getSpecified())) { return null; } return value; }

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS> public Object getBaseValue() { return attr; } public boolean isCollection() { return false; } public int getLength() { return 1; } public Object getImmediateNode() { return attr; } public boolean isActual() { return true; } public boolean isLeaf() { return true; } public boolean testNode(NodeTest nodeTest) { return nodeTest == null || ((nodeTest instanceof NodeTypeTest) && ((NodeTypeTest) nodeTest).getNodeType() == Compiler.NODE_TYPE_NODE); } /** * Sets the value of this attribute. */ public void setValue(Object value) { attr.setValue((String) TypeUtils.convert(value, String.class)); } public void remove() { attr.getOwnerElement().removeAttributeNode(attr); } /** */ public String asPath() { StringBuffer buffer = new StringBuffer(); if (parent != null) { buffer.append(parent.asPath()); if (buffer.length() == 0 || buffer.charAt(buffer.length() - 1) != '/') { buffer.append('/'); } } buffer.append('@'); buffer.append(getName()); return buffer.toString(); } public int hashCode() { return System.identityHashCode(attr); } public boolean equals(Object object) { return object == this || object instanceof DOMAttributePointer && attr == ((DOMAttributePointer) object).attr; } public int compareChildNodePointers( NodePointer pointer1, NodePointer pointer2) { // Won't happen - attributes don't have children return 0; } }

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri; import org.apache.commons.jxpath.Pointer; import org.apache.commons.jxpath.ri.model.NodePointer; import org.apache.commons.jxpath.ri.model.VariablePointer; /** * Type conversions, XPath style. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class InfoSetUtil { private static final Double ZERO = new Double(0); private static final Double ONE = new Double(1); private static final Double NOT_A_NUMBER = new Double(Double.NaN); /** * Converts the supplied object to String */ public static String stringValue(Object object) { if (object instanceof String) { return (String) object; } if (object instanceof Number) { double d = ((Number) object).doubleValue(); long l = ((Number) object).longValue(); return d == l ? String.valueOf(l) : String.valueOf(d); } if (object instanceof Boolean) { return ((Boolean) object).booleanValue() ? "true" : "false"; } if (object == null) { return ""; } if (object instanceof NodePointer) { return stringValue(((NodePointer) object).getValue()); } if (object instanceof EvalContext) { EvalContext ctx = (EvalContext) object; Pointer ptr = ctx.getSingle

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>NodePointer(); return ptr == null ? "" : stringValue(ptr); } return String.valueOf(object); } /** * Converts the supplied object to Number */ public static Number number(Object object) { if (object instanceof Number) { return (Number) object; } if (object instanceof Boolean) { return ((Boolean) object).booleanValue() ? ONE : ZERO; } if (object instanceof String) { try { return new Double((String) object); } catch (NumberFormatException ex) { return NOT_A_NUMBER; } } if (object instanceof EvalContext) { EvalContext ctx = (EvalContext) object; Pointer ptr = ctx.getSingleNodePointer(); return ptr == null ? NOT_A_NUMBER : number(ptr); } if (object instanceof NodePointer) { return number(((NodePointer) object).getValue()); } return number(stringValue(object)); } /** * Converts the supplied object to double */ public static double doubleValue(Object object) { if (object instanceof Number) { return ((Number) object).doubleValue(); } if (object instanceof Boolean) { return ((Boolean) object).booleanValue() ? 0.0 : 1.0; } if (object instanceof String) { if (object.equals("")) { return 0.0; } try { return Double.parseDouble((String) object); } catch (NumberFormatException ex) { return Double.NaN; } } if (object instanceof NodePointer) { return doubleValue(((NodePointer) object).getValue()); } if (object instanceof EvalContext) { EvalContext ctx = (EvalContext) object; Pointer ptr = ctx.getSingleNodePointer(); return ptr == null ? Double.NaN : doubleValue(ptr); } return doubleValue(stringValue(object)); } /** * Converts the supplied object to boolean */ public static boolean booleanValue(Object object) { if (object instanceof Number) { double value = ((Number) object).doubleValue(); return value != 0 && value != -0 && !Double.isNaN(value); } if (object instanceof Boolean) { return ((Boolean) object).booleanValue();

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS> } if (object instanceof EvalContext) { EvalContext ctx = (EvalContext) object; Pointer ptr = ctx.getSingleNodePointer(); return ptr == null ? false : booleanValue(ptr); } if (object instanceof String) { return ((String) object).length() != 0; } if (object instanceof NodePointer) { NodePointer pointer = (NodePointer) object; if (pointer instanceof VariablePointer) { return booleanValue(pointer.getNode()); } pointer = pointer.getValuePointer(); return pointer.isActual(); } return object != null; } }

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.axes; import org.apache.commons.jxpath.Pointer; import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.model.NodePointer; /** * A single-set EvalContext that provides access to the current node of * the parent context and nothing else. It does not pass the iteration * on to the parent context. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class InitialContext extends EvalContext { private boolean started = false; private boolean collection; private NodePointer nodePointer; public InitialContext(EvalContext parentContext) { super(parentContext); nodePointer = (NodePointer) parentContext.getCurrentNodePointer().clone(); if (nodePointer != null) { collection = (nodePointer.getIndex() == NodePointer.WHOLE_COLLECTION); } } public Pointer getSingleNodePointer() { return nodePointer; } public NodePointer getCurrentNodePointer() { return nodePointer; } public Object getValue() { return nodePointer.getValue(); } public boolean nextNode() { return setPosition(position + 1); } public boolean setPosition(int position) { this.position = position; if (collection) { if (position >= 1 && position <= nodePointer.getLength())

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.axes; import org.apache.commons.jxpath.NodeSet; import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.model.NodePointer; /** * A simple context that is based on a NodeSet. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class NodeSetContext extends EvalContext { private boolean startedSet = false; private NodeSet nodeSet; public NodeSetContext(EvalContext parentContext, NodeSet nodeSet) { super(parentContext); this.nodeSet = nodeSet; } public NodeSet getNodeSet() { return nodeSet; } public NodePointer getCurrentNodePointer() { if (position == 0) { if (!setPosition(1)) { return null; } } return (NodePointer) nodeSet.getPointers().get(position - 1); } public boolean setPosition(int position) { super.setPosition(position); return position >= 1 && position <= nodeSet.getPointers().size(); } public boolean nextSet() { if (startedSet) { return false; } startedSet = true; return true; } public boolean nextNode() { return setPosition(position + 1); } }

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.beans; import java.util.Locale; import org.apache.commons.jxpath.JXPathBeanInfo; import org.apache.commons.jxpath.JXPathIntrospector; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.model.NodePointer; /** * A Pointer that points to a JavaBean or a collection. It is either * the first element of a path or a pointer for a property value. * Typically there is a BeanPropertyPointer between two BeanPointers * in the chain. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class BeanPointer extends PropertyOwnerPointer { private QName name; private Object bean; private JXPathBeanInfo beanInfo; public BeanPointer( QName name, Object bean, JXPathBeanInfo beanInfo, Locale locale) { super(null, locale); this.name = name; this.bean = bean; this.beanInfo = beanInfo; } /** * @param name is the name given to the first node */ public BeanPointer( NodePointer parent, QName name, Object bean, JXPathBeanInfo beanInfo) { super(parent); this.name = name; this.bean = bean; this.beanInfo = bean

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model; /** * Definition for an iterator for all kinds of Nodes. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public interface NodeIterator { int getPosition(); /** * Sets the new current position and returns true if there a node * at that position. */ boolean setPosition(int position); NodePointer getNodePointer(); }

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.dom; import java.util.ArrayList; import java.util.List; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.model.NodeIterator; import org.apache.commons.jxpath.ri.model.NodePointer; import org.w3c.dom.Attr; import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; /** * An iterator of attributes of a DOM Node. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class DOMAttributeIterator implements NodeIterator { private NodePointer parent; private QName name; private List attributes; private int position = 0; public DOMAttributeIterator(NodePointer parent, QName name) { this.parent = parent; this.name = name; attributes = new ArrayList(); Node node = (Node) parent.getNode(); if (node.getNodeType() == Node.ELEMENT_NODE) { String lname = name.getName(); if (!lname.equals("*")) { Attr attr = getAttribute((Element) node, name); if (attr != null) { attributes.add(attr); } } else { NamedNodeMap map = node.getAttributes

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS> if (testAttr(attr, name)) { return attr; } } return null; } return element.getAttributeNode(name.getName()); } public NodePointer getNodePointer() { if (position == 0) { if (!setPosition(1)) { return null; } position = 0; } int index = position - 1; if (index < 0) { index = 0; } return new DOMAttributePointer(parent, (Attr) attributes.get(index)); } public int getPosition() { return position; } public boolean setPosition(int position) { this.position = position; return position >= 1 && position <= attributes.size(); } }

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.dynamic; import java.util.Locale; import org.apache.commons.jxpath.DynamicPropertyHandler; import org.apache.commons.jxpath.JXPathIntrospector; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.model.NodeIterator; import org.apache.commons.jxpath.ri.model.NodePointer; import org.apache.commons.jxpath.ri.model.beans.PropertyIterator; import org.apache.commons.jxpath.ri.model.beans.PropertyOwnerPointer; import org.apache.commons.jxpath.ri.model.beans.PropertyPointer; /** * A Pointer that points to an object with Dynamic Properties. It is used for * the first element of a path; following elements will by of type * PropertyPointer. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class DynamicPointer extends PropertyOwnerPointer { private QName name; private Object bean; private DynamicPropertyHandler handler; public DynamicPointer(QName name, Object bean, DynamicPropertyHandler handler, Locale locale) { super(null, locale); this.name = name; this.bean = bean; this.handler = handler; } public DynamicPointer(NodePointer parent, QName name, Object bean,

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS> DynamicPropertyHandler handler) { super(parent); this.name = name; this.bean = bean; this.handler = handler; } public PropertyPointer getPropertyPointer() { return new DynamicPropertyPointer(this, handler); } public NodeIterator createNodeIterator( String property, boolean reverse, NodePointer startWith) { return new PropertyIterator(this, property, reverse, startWith); } public NodeIterator attributeIterator(QName name) { return new DynamicAttributeIterator(this, name); } public QName getName() { return name; } public boolean isDynamicPropertyDeclarationSupported() { return true; } /** * Returns the DP object iself. */ public Object getBaseValue() { return bean; } public boolean isLeaf() { Object value = getNode(); return value == null || JXPathIntrospector.getBeanInfo(value.getClass()).isAtomic(); } public boolean isCollection() { return false; } /** * Returns 1. */ public int getLength() { return 1; } public String asPath() { return parent == null ? "/" : super.asPath(); } public int hashCode() { return System.identityHashCode(bean) + name.hashCode(); } public boolean equals(Object object) { if (object == this) { return true; } if (!(object instanceof DynamicPointer)) { return false; } DynamicPointer other = (DynamicPointer) object; return bean == other.bean && name.equals(other.name); } }

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>parentContext); String propertyName = InfoSetUtil.stringValue(pred); // At this point it would be nice to say: // dynamicPropertyPointer.setPropertyName(propertyName) // and then: dynamicPropertyPointer.isActual(). // However some PropertyPointers, e.g. DynamicPropertyPointer // will declare that any property you ask for is actual. // That's not acceptable for us: we really need to know // if the property is currently declared. Thus, // we'll need to perform a search. boolean ok = false; String names[] = dynamicPropertyPointer.getPropertyNames(); for (int i = 0; i < names.length; i++) { if (names[i].equals(propertyName)) { ok = true; break; } } if (ok) { dynamicPropertyPointer.setPropertyName(propertyName); position++; return true; } } else { Object pred = expression.computeValue(parentContext); if (pred instanceof Iterator) { if (!((Iterator) pred).hasNext()) { return false; } pred = ((Iterator) pred).next(); } if (pred instanceof NodePointer) { pred = ((NodePointer) pred).getNode(); } if (pred instanceof Number) { int pos = (int) InfoSetUtil.doubleValue(pred); position++; done = true; return parentContext.setPosition(pos); } if (InfoSetUtil.booleanValue(pred)) { position++; return true; } } } return false; } /** * Used for an optimized access to dynamic properties using the * "map[@name = 'name']" syntax */ private boolean setupDynamicPropertyPointer() { if (nameTestExpression == null) { return false; } NodePointer parent = parentContext.getCurrentNodePointer(); if (parent == null) { return false; } parent = parent.getValuePointer(); if (!(parent instanceof PropertyOwnerPointer)) { return false; } dynamicPropertyPointer = (PropertyPointer) ((PropertyOwnerPointer) parent) .getPropertyPointer() .clone(); return true; } public boolean setPosition(int position) { if (nameTestExpression == null) { return setPositionStandard(position

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>); } else { if (dynamicPropertyPointer == null) { if (!setupDynamicPropertyPointer()) { return setPositionStandard(position); } } if (position < 1 || position > dynamicPropertyPointer.getLength()) { return false; } dynamicPropertyPointer.setIndex(position - 1); return true; } } public NodePointer getCurrentNodePointer() { if (position == 0) { if (!setPosition(1)) { return null; } } if (dynamicPropertyPointer != null) { return dynamicPropertyPointer.getValuePointer(); } return parentContext.getCurrentNodePointer(); } public void reset() { super.reset(); parentContext.reset(); done = false; } public boolean nextSet() { reset(); return parentContext.nextSet(); } private boolean setPositionStandard(int position) { if (this.position > position) { reset(); } while (this.position < position) { if (!nextNode()) { return false; } } return true; } }

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.beans; import java.util.Locale; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.JXPathIntrospector; import org.apache.commons.jxpath.ri.Compiler; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.compiler.NodeNameTest; import org.apache.commons.jxpath.ri.compiler.NodeTest; import org.apache.commons.jxpath.ri.compiler.NodeTypeTest; import org.apache.commons.jxpath.ri.model.NodeIterator; import org.apache.commons.jxpath.ri.model.NodePointer; import org.apache.commons.jxpath.util.ValueUtils; /** * Transparent pointer to a collection (array or Collection). * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class CollectionPointer extends NodePointer { private Object collection; private NodePointer valuePointer; public CollectionPointer(Object collection, Locale locale) { super(null, locale); this.collection = collection; } public CollectionPointer(NodePointer parent, Object collection) { super(parent); this.collection = collection; } public QName getName() { return null; } public Object getBaseValue() {

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS> return collection; } public boolean isCollection() { return true; } public int getLength() { return ValueUtils.getLength(getBaseValue()); } public boolean isLeaf() { Object value = getNode(); return value == null || JXPathIntrospector.getBeanInfo(value.getClass()).isAtomic(); } public boolean isContainer() { return index != WHOLE_COLLECTION; } public Object getImmediateNode() { return index == WHOLE_COLLECTION ? ValueUtils.getValue(collection) : ValueUtils.getValue(collection, index); } public void setValue(Object value) { if (index == WHOLE_COLLECTION) { parent.setValue(value); } else { ValueUtils.setValue(collection, index, value); } } public void setIndex(int index) { super.setIndex(index); valuePointer = null; } public NodePointer getValuePointer() { if (valuePointer == null) { if (index == WHOLE_COLLECTION) { valuePointer = this; } else { Object value = getImmediateNode(); valuePointer = NodePointer.newChildNodePointer(this, getName(), value); } } return valuePointer; } public NodePointer createPath(JXPathContext context) { Object collection = getBaseValue(); if (ValueUtils.getLength(collection) <= index) { collection = ValueUtils.expandCollection(getNode(), index + 1); } return this; } public NodePointer createPath(JXPathContext context, Object value) { NodePointer ptr = createPath(context); ptr.setValue(value); return ptr; } public NodePointer createChild( JXPathContext context, QName name, int index, Object value) { NodePointer ptr = (NodePointer) clone(); ptr.setIndex(index); return ptr.createPath(context, value); } public NodePointer createChild( JXPathContext context, QName name, int index) { NodePointer ptr = (NodePointer) clone(); ptr.setIndex(index); return ptr.createPath(context); } public int hashCode() { return System.identityHashCode(collection

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>) + index; } public boolean equals(Object object) { if (object == this) { return true; } if (!(object instanceof CollectionPointer)) { return false; } CollectionPointer other = (CollectionPointer) object; return collection == other.collection && index == other.index; } public NodeIterator childIterator(NodeTest test, boolean reverse, NodePointer startWith) { if (index == WHOLE_COLLECTION) { return new CollectionChildNodeIterator( this, test, reverse, startWith); } return getValuePointer().childIterator(test, reverse, startWith); } public NodeIterator attributeIterator(QName name) { return index == WHOLE_COLLECTION ? new CollectionAttributeNodeIterator(this, name) : getValuePointer().attributeIterator(name); } public NodeIterator namespaceIterator() { return index == WHOLE_COLLECTION ? null : getValuePointer().namespaceIterator(); } public NodePointer namespacePointer(String namespace) { return index == WHOLE_COLLECTION ? null : getValuePointer().namespacePointer(namespace); } public boolean testNode(NodeTest test) { if (index == WHOLE_COLLECTION) { if (test == null) { return true; } if (test instanceof NodeNameTest) { return false; } return test instanceof NodeTypeTest && ((NodeTypeTest) test).getNodeType() == Compiler.NODE_TYPE_NODE; } return getValuePointer().testNode(test); } public int compareChildNodePointers( NodePointer pointer1, NodePointer pointer2) { return pointer1.getIndex() - pointer2.getIndex(); } /** * Returns an XPath that maps to this Pointer. */ public String asPath() { StringBuffer buffer = new StringBuffer(); NodePointer parent = getImmediateParentPointer(); if (parent != null) { buffer.append(parent.asPath()); if (index != WHOLE_COLLECTION) { // Address the list[1][2] case if (parent.getIndex() != WHOLE_COLLECTION) { buffer.append("/."); } buffer.append("[").append(index + 1).append(']'); } } else { if (index

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>.JDOMPointerFactory", "org.jdom.Document"); if (jdomFactory != null) { nodeFactories.add(jdomFactory); } // DynaBean factory is only registered if BeanUtils are on the classpath Object dynaBeanFactory = allocateConditionally( "org.apache.commons.jxpath.ri.model.dynabeans." + "DynaBeanPointerFactory", "org.apache.commons.beanutils.DynaBean"); if (dynaBeanFactory != null) { nodeFactories.add(dynaBeanFactory); } nodeFactories.add(new ContainerPointerFactory()); createNodeFactoryArray(); } private Pointer rootPointer; private Pointer contextPointer; protected NamespaceResolver namespaceResolver; private String defaultNamespaceURI; // The frequency of the cache cleanup private static final int CLEANUP_THRESHOLD = 500; protected JXPathContextReferenceImpl(JXPathContext parentContext, Object contextBean) { this(parentContext, contextBean, null); } public JXPathContextReferenceImpl( JXPathContext parentContext, Object contextBean, Pointer contextPointer) { super(parentContext, contextBean); synchronized (nodeFactories) { createNodeFactoryArray(); } if (contextPointer != null) { this.contextPointer = contextPointer; this.rootPointer = NodePointer.newNodePointer( new QName(null, "root"), contextPointer.getRootNode(), getLocale()); } else { this.contextPointer = NodePointer.newNodePointer( new QName(null, "root"), contextBean, getLocale()); this.rootPointer = this.contextPointer; } NamespaceResolver parentNR = null; if (parentContext instanceof JXPathContextReferenceImpl) { parentNR = ((JXPathContextReferenceImpl)parentContext).getNamespaceResolver(); } namespaceResolver = new NamespaceResolver(parentNR); namespaceResolver .setNamespaceContextPointer((NodePointer) this.contextPointer); } private static void createNodeFactoryArray() { if (nodeFactoryArray == null) { nodeFactoryArray = (NodePointerFactory[]) nodeFactories. toArray(new NodePointerFactory[0]); Arrays.sort(node

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>) { // return (Node)bean; // } // // if (bean instanceof Container) { // bean = ((Container)bean).getValue(); // return getNativeContextNode(bean); // } // // return null; // } public Object getValue(String xpath, Expression expr) { Object result = expr.computeValue(getEvalContext()); if (result == null) { if (expr instanceof Path) { if (!isLenient()) { throw new JXPathNotFoundException("No value for xpath: " + xpath); } } return null; } if (result instanceof EvalContext) { EvalContext ctx = (EvalContext) result; result = ctx.getSingleNodePointer(); if (!isLenient() && result == null) { throw new JXPathNotFoundException("No value for xpath: " + xpath); } } if (result instanceof NodePointer) { result = ((NodePointer) result).getValuePointer(); if (!isLenient() && !((NodePointer) result).isActual()) { // We need to differentiate between pointers representing // a non-existing property and ones representing a property // whose value is null. In the latter case, the pointer // is going to have isActual == false, but its parent, // which is a non-node pointer identifying the bean property, // will return isActual() == true. NodePointer parent = ((NodePointer) result).getImmediateParentPointer(); if (parent == null || !parent.isContainer() || !parent.isActual()) { throw new JXPathNotFoundException("No value for xpath: " + xpath); } } result = ((NodePointer) result).getValue(); } return result; } /** * Calls getValue(xpath), converts the result to the required type * and returns the result of the conversion. */ public Object getValue(String xpath, Class requiredType) { Expression expr = compileExpression(xpath); return getValue(xpath, expr, requiredType); } public Object getValue(String xpath, Expression expr, Class requiredType) { Object value = getValue(xpath, expr); if (value != null && requiredType != null) { if

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS> (!TypeUtils.canConvert(value, requiredType)) { throw new JXPathTypeConversionException( "Invalid expression type. '" + xpath + "' returns " + value.getClass().getName() + ". It cannot be converted to " + requiredType.getName()); } value = TypeUtils.convert(value, requiredType); } return value; } /** * Traverses the xpath and returns a Iterator of all results found * for the path. If the xpath matches no properties * in the graph, the Iterator will not be null. */ public Iterator iterate(String xpath) { return iterate(xpath, compileExpression(xpath)); } public Iterator iterate(String xpath, Expression expr) { return expr.iterate(getEvalContext()); } public Pointer getPointer(String xpath) { return getPointer(xpath, compileExpression(xpath)); } public Pointer getPointer(String xpath, Expression expr) { Object result = expr.computeValue(getEvalContext()); if (result instanceof EvalContext) { result = ((EvalContext) result).getSingleNodePointer(); } if (result instanceof Pointer) { if (!isLenient() && !((NodePointer) result).isActual()) { throw new JXPathNotFoundException("No pointer for xpath: " + xpath); } return (Pointer) result; } return NodePointer.newNodePointer(null, result, getLocale()); } public void setValue(String xpath, Object value) { setValue(xpath, compileExpression(xpath), value); } public void setValue(String xpath, Expression expr, Object value) { try { setValue(xpath, expr, value, false); } catch (Throwable ex) { throw new JXPathException( "Exception trying to set value with xpath " + xpath, ex); } } public Pointer createPath(String xpath) { return createPath(xpath, compileExpression(xpath)); } public Pointer createPath(String xpath, Expression expr) { try { Object result = expr.computeValue(getEvalContext()); Pointer pointer = null; if (result instanceof Pointer) { pointer = (Pointer) result; } else if (result instanceof EvalContext) { EvalContext ctx = (EvalContext) result

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>; pointer = ctx.getSingleNodePointer(); } else { checkSimplePath(expr); // This should never happen throw new JXPathException("Cannot create path:" + xpath); } return ((NodePointer) pointer).createPath(this); } catch (Throwable ex) { throw new JXPathException( "Exception trying to create xpath " + xpath, ex); } } public Pointer createPathAndSetValue(String xpath, Object value) { return createPathAndSetValue(xpath, compileExpression(xpath), value); } public Pointer createPathAndSetValue( String xpath, Expression expr, Object value) { try { return setValue(xpath, expr, value, true); } catch (Throwable ex) { throw new JXPathException( "Exception trying to create xpath " + xpath, ex); } } private Pointer setValue( String xpath, Expression expr, Object value, boolean create) { Object result = expr.computeValue(getEvalContext()); Pointer pointer = null; if (result instanceof Pointer) { pointer = (Pointer) result; } else if (result instanceof EvalContext) { EvalContext ctx = (EvalContext) result; pointer = ctx.getSingleNodePointer(); } else { if (create) { checkSimplePath(expr); } // This should never happen throw new JXPathException("Cannot set value for xpath: " + xpath); } if (create) { pointer = ((NodePointer) pointer).createPath(this, value); } else { pointer.setValue(value); } return pointer; } /** * Checks if the path follows the JXPath restrictions on the type * of path that can be passed to create... methods. */ private void checkSimplePath(Expression expr) { if (!(expr instanceof LocationPath) || !((LocationPath) expr).isSimplePath()) { throw new JXPathInvalidSyntaxException( "JXPath can only create a path if it uses exclusively " + "the child:: and attribute:: axes and has " + "no context-dependent predicates"); } } /** * Traverses the xpath and returns an Iterator of Pointers. * A Pointer

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS> provides easy access to a property. * If the xpath matches no properties * in the graph, the Iterator be empty, but not null. */ public Iterator iteratePointers(String xpath) { return iteratePointers(xpath, compileExpression(xpath)); } public Iterator iteratePointers(String xpath, Expression expr) { return expr.iteratePointers(getEvalContext()); } public void removePath(String xpath) { removePath(xpath, compileExpression(xpath)); } public void removePath(String xpath, Expression expr) { try { NodePointer pointer = (NodePointer) getPointer(xpath, expr); if (pointer != null) { ((NodePointer) pointer).remove(); } } catch (Throwable ex) { throw new JXPathException( "Exception trying to remove xpath " + xpath, ex); } } public void removeAll(String xpath) { removeAll(xpath, compileExpression(xpath)); } public void removeAll(String xpath, Expression expr) { try { ArrayList list = new ArrayList(); Iterator it = expr.iteratePointers(getEvalContext()); while (it.hasNext()) { list.add(it.next()); } Collections.sort(list, ReverseComparator.INSTANCE); it = list.iterator(); if (it.hasNext()) { NodePointer pointer = (NodePointer) it.next(); pointer.remove(); while (it.hasNext()) { removePath(((NodePointer) it.next()).asPath()); } } } catch (Throwable ex) { throw new JXPathException( "Exception trying to remove all for xpath " + xpath, ex); } } public JXPathContext getRelativeContext(Pointer pointer) { Object contextBean = pointer.getNode(); if (contextBean == null) { throw new JXPathException( "Cannot create a relative context for a non-existent node: " + pointer); } return new JXPathContextReferenceImpl(this, contextBean, pointer); } public Pointer getContextPointer() { return contextPointer; } private NodePointer getAbsoluteRootPointer() { return (NodePointer) rootPointer; } private EvalContext getEvalContext() { return new InitialContext(new RootContext(this,

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS> (NodePointer) getContextPointer())); } public EvalContext getAbsoluteRootContext() { return new InitialContext(new RootContext(this, getAbsoluteRootPointer())); } public NodePointer getVariablePointer(QName name) { String varName = name.toString(); JXPathContext varCtx = this; Variables vars = null; while (varCtx != null) { vars = varCtx.getVariables(); if (vars.isDeclaredVariable(varName)) { break; } varCtx = varCtx.getParentContext(); vars = null; } if (vars != null) { return new VariablePointer(vars, name); } else { // The variable is not declared, but we will create // a pointer anyway in case the user want to set, rather // than get, the value of the variable. return new VariablePointer(name); } } public Function getFunction(QName functionName, Object[] parameters) { String namespace = functionName.getPrefix(); String name = functionName.getName(); JXPathContext funcCtx = this; Function func = null; Functions funcs; while (funcCtx != null) { funcs = funcCtx.getFunctions(); if (funcs != null) { func = funcs.getFunction(namespace, name, parameters); if (func != null) { return func; } } funcCtx = funcCtx.getParentContext(); } throw new JXPathFunctionNotFoundException( "Undefined function: " + functionName.toString()); } public void registerNamespace(String prefix, String namespaceURI) { if (namespaceResolver.isSealed()) { namespaceResolver = (NamespaceResolver) namespaceResolver.clone(); } namespaceResolver.registerNamespace(prefix, namespaceURI); } public String getNamespaceURI(String prefix) { return namespaceResolver.getNamespaceURI(prefix); } public void setNamespaceContextPointer(Pointer pointer) { if (namespaceResolver.isSealed()) { namespaceResolver = (NamespaceResolver) namespaceResolver.clone(); } namespaceResolver.setNamespaceContextPointer((NodePointer) pointer); } public Pointer getNamespaceContextPointer() { return namespaceResolver.getNamespaceContextPointer(); } public NamespaceResolver getNamespaceResolver() { namespaceResolver.se

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.jdom; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.model.NodePointer; /** * Represents a namespace node. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class JDOMNamespacePointer extends NodePointer { private String prefix; private String namespaceURI; public JDOMNamespacePointer(NodePointer parent, String prefix) { super(parent); this.prefix = prefix; } public JDOMNamespacePointer( NodePointer parent, String prefix, String namespaceURI) { super(parent); this.prefix = prefix; this.namespaceURI = namespaceURI; } public QName getName() { return new QName(prefix); } public Object getBaseValue() { return null; } public boolean isCollection() { return false; } public int getLength() { return 1; } public Object getImmediateNode() { return getNamespaceURI(); } public String getNamespaceURI() { if (namespaceURI == null) { namespaceURI = parent.getNamespaceURI(prefix); } return namespaceURI; } public boolean isLeaf() { return true; } /** * Throws UnsupportedOperationException. */ public void setValue(Object value) { throw new UnsupportedOperationException("Cannot

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS> modify a namespace"); } public String asPath() { StringBuffer buffer = new StringBuffer(); if (parent != null) { buffer.append(parent.asPath()); if (buffer.length() == 0 || buffer.charAt(buffer.length() - 1) != '/') { buffer.append('/'); } } buffer.append("namespace::"); buffer.append(prefix); return buffer.toString(); } public int hashCode() { return prefix.hashCode(); } public boolean equals(Object object) { return object == this || object instanceof JDOMNamespacePointer && prefix.equals(((JDOMNamespacePointer) object).prefix); } public int compareChildNodePointers( NodePointer pointer1, NodePointer pointer2) { // Won't happen - namespaces don't have children return 0; } }

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>Iteration = false; private boolean done = false; private boolean hasPerformedIteratorStep = false; private Iterator pointerIterator; public EvalContext(EvalContext parentContext) { this.parentContext = parentContext; } public Pointer getContextNodePointer() { return getCurrentNodePointer(); } public JXPathContext getJXPathContext() { return getRootContext().getJXPathContext(); } public int getPosition() { return position; } /** * Determines the document order for this context. * * @return 1 ascending order, -1 descending order, * 0 - does not require ordering */ public int getDocumentOrder() { return parentContext != null && parentContext.isChildOrderingRequired() ? 1 : 0; } /** * Even if this context has the natural ordering and therefore does * not require collecting and sorting all nodes prior to returning them, * such operation may be required for any child context. */ public boolean isChildOrderingRequired() { // Default behavior: if this context needs to be ordered, // the children need to be ordered too return getDocumentOrder() != 0; } /** * Returns true if there are mode nodes matching the context's constraints. */ public boolean hasNext() { if (pointerIterator != null) { return pointerIterator.hasNext(); } if (getDocumentOrder() != 0) { return constructIterator(); } if (!done && !hasPerformedIteratorStep) { performIteratorStep(); } return !done; } /** * Returns the next node pointer in the context */ public Object next() { if (pointerIterator != null) { return pointerIterator.next(); } if (getDocumentOrder() != 0) { if (!constructIterator()) { throw new NoSuchElementException(); } return pointerIterator.next(); } if (!done && !hasPerformedIteratorStep) { performIteratorStep(); } if (done) { throw new NoSuchElementException(); } hasPerformedIteratorStep = false; return getCurrentNodePointer(); } /** * Moves the iterator forward by one position */ private void performIteratorStep() { done = true; if (position != 0 && nextNode()) {

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS> done = false; } else { while (nextSet()) { if (nextNode()) { done = false; break; } } } hasPerformedIteratorStep = true; } /** * Operation is not supported */ public void remove() { throw new UnsupportedOperationException( "JXPath iterators cannot remove nodes"); } private boolean constructIterator() { HashSet set = new HashSet(); ArrayList list = new ArrayList(); while (nextSet()) { while (nextNode()) { NodePointer pointer = getCurrentNodePointer(); if (!set.contains(pointer)) { set.add(pointer); list.add(pointer); } } } if (list.isEmpty()) { return false; } if (getDocumentOrder() == 1) { Collections.sort(list); } else { Collections.sort(list, ReverseComparator.INSTANCE); } pointerIterator = list.iterator(); return true; } /** * Returns the list of all Pointers in this context for the current * position of the parent context. */ public List getContextNodeList() { int pos = position; if (pos != 0) { reset(); } List list = new ArrayList(); while (nextNode()) { list.add(getCurrentNodePointer()); } if (pos != 0) { setPosition(pos); } else { reset(); } return list; } /** * Returns the list of all Pointers in this context for all positions * of the parent contexts. If there was an ongoing iteration over * this context, the method should not be called. */ public NodeSet getNodeSet() { if (position != 0) { throw new JXPathException( "Simultaneous operations: " + "should not request pointer list while " + "iterating over an EvalContext"); } BasicNodeSet set = new BasicNodeSet(); while (nextSet()) { while (nextNode()) { set.add((Pointer)getCurrentNodePointer().clone()); } } return set; } /** * Typically returns the NodeSet by calling getNodeSet(), * but will be overridden for contexts that more naturally produce * individual values, e

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>.g. VariableContext */ public Object getValue() { return getNodeSet(); } public String toString() { Pointer ptr = getContextNodePointer(); return ptr == null ? "Empty expression context" : "Expression context [" + getPosition() + "] " + ptr.asPath(); } /** * Returns the root context of the path, which provides easy * access to variables and functions. */ public RootContext getRootContext() { if (rootContext == null) { rootContext = parentContext.getRootContext(); } return rootContext; } /** * Sets current position = 0, which is the pre-iteration state. */ public void reset() { position = 0; } public int getCurrentPosition() { return position; } /** * Returns the first encountered Pointer that matches the current * context's criteria. */ public Pointer getSingleNodePointer() { reset(); while (nextSet()) { if (nextNode()) { return getCurrentNodePointer(); } } return null; } /** * Returns the current context node. Undefined before the beginning * of the iteration. */ public abstract NodePointer getCurrentNodePointer(); /** * Returns true if there is another sets of objects to interate over. * Resets the current position and node. */ public boolean nextSet() { reset(); // Restart iteration within the set // Most of the time you have one set per parent node // First time this method is called, we should look for // the first parent set that contains at least one node. if (!startedSetIteration) { startedSetIteration = true; while (parentContext.nextSet()) { if (parentContext.nextNode()) { return true; } } return false; } // In subsequent calls, we see if the parent context // has any nodes left in the current set if (parentContext.nextNode()) { return true; } // If not, we look for the next set that contains // at least one node while (parentContext.nextSet()) { if (parentContext.nextNode()) { return true; } } return false; } /** * Returns true if there is another object in the current

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS> set. * Switches the current position and node to the next object. */ public abstract boolean nextNode(); /** * Moves the current position to the specified index. Used with integer * predicates to quickly get to the n'th element of the node set. * Returns false if the position is out of the node set range. * You can call it with 0 as the position argument to restart the iteration. */ public boolean setPosition(int position) { this.position = position; return true; } }

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.beans; import java.util.Locale; import org.apache.commons.jxpath.JXPathBeanInfo; import org.apache.commons.jxpath.JXPathIntrospector; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.model.NodePointer; import org.apache.commons.jxpath.ri.model.NodePointerFactory; /** * Implements NodePointerFactory for JavaBeans. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class BeanPointerFactory implements NodePointerFactory { public static final int BEAN_POINTER_FACTORY_ORDER = 900; public int getOrder() { return BEAN_POINTER_FACTORY_ORDER; } public NodePointer createNodePointer( QName name, Object bean, Locale locale) { JXPathBeanInfo bi = JXPathIntrospector.getBeanInfo(bean.getClass()); return new BeanPointer(name, bean, bi, locale); } public NodePointer createNodePointer( NodePointer parent, QName name, Object bean) { if (bean == null) { return new NullPointer(parent, name); } JXPathBeanInfo bi = JXPathIntrospector.getBeanInfo(bean.getClass()); return new BeanPointer(parent, name, bean

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.container; import java.util.Locale; import org.apache.commons.jxpath.Container; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.model.NodePointer; import org.apache.commons.jxpath.ri.model.NodePointerFactory; /** * Implements NodePointerFactory for Container objects. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class ContainerPointerFactory implements NodePointerFactory { public static final int CONTAINER_POINTER_FACTORY_ORDER = 200; public int getOrder() { return CONTAINER_POINTER_FACTORY_ORDER; } public NodePointer createNodePointer( QName name, Object bean, Locale locale) { return bean instanceof Container ? new ContainerPointer((Container) bean, locale) : null; } public NodePointer createNodePointer( NodePointer parent, QName name, Object bean) { return bean instanceof Container ? new ContainerPointer(parent, (Container) bean) : null; } }

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.jdom; import java.util.Locale; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.model.NodePointer; import org.apache.commons.jxpath.ri.model.NodePointerFactory; import org.jdom.Document; import org.jdom.Element; /** * Implements NodePointerFactory for DOM elements. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class JDOMPointerFactory implements NodePointerFactory { public static final int JDOM_POINTER_FACTORY_ORDER = 110; public int getOrder() { return JDOM_POINTER_FACTORY_ORDER; } public NodePointer createNodePointer( QName name, Object bean, Locale locale) { if (bean instanceof Document) { return new JDOMNodePointer(bean, locale); } if (bean instanceof Element) { return new JDOMNodePointer(bean, locale); } return null; } public NodePointer createNodePointer( NodePointer parent, QName name, Object bean) { if (bean instanceof Document) { return new JDOMNodePointer(parent, bean); } if (bean instanceof Element) { return new JDOMNodePointer(parent, bean); } return null; } }

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.axes; import org.apache.commons.jxpath.Pointer; import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.compiler.NodeTest; import org.apache.commons.jxpath.ri.model.NodePointer; /** * EvalContext that returns the current node from the parent context if the * test succeeds. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class SelfContext extends EvalContext { private NodeTest nodeTest; private boolean startedSet = false; private NodePointer nodePointer; public SelfContext(EvalContext parentContext, NodeTest nodeTest) { super(parentContext); this.nodeTest = nodeTest; } public Pointer getSingleNodePointer() { return parentContext.getSingleNodePointer(); } public NodePointer getCurrentNodePointer() { if (position == 0) { if (!setPosition(1)) { return null; } } return nodePointer; } public boolean nextNode() { return setPosition(getCurrentPosition() + 1); } public void reset() { super.reset(); startedSet = false; } public boolean setPosition(int position) { if (position != 1) { return false; } super.setPosition(position); if (!

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>startedSet) { startedSet = true; nodePointer = (NodePointer) parentContext.getCurrentNodePointer(); } if (nodePointer == null) { return false; } return nodeTest == null || nodePointer.testNode(nodeTest); } }

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.axes; import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.compiler.NodeTest; import org.apache.commons.jxpath.ri.model.NodePointer; /** * EvalContext that walks the "parent::" axis. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class ParentContext extends EvalContext { private NodeTest nodeTest; private boolean setStarted = false; private NodePointer currentNodePointer; public ParentContext(EvalContext parentContext, NodeTest nodeTest) { super(parentContext); this.nodeTest = nodeTest; } public NodePointer getCurrentNodePointer() { return currentNodePointer; } public int getCurrentPosition() { return 1; } public int getDocumentOrder() { return -1; } public void reset() { super.reset(); setStarted = false; } public boolean setPosition(int position) { super.setPosition(position); return position == 1; } public boolean nextNode() { // Each set contains exactly one node: the parent if (setStarted) { return false; } setStarted = true; NodePointer thisLocation = parentContext.getCurrentNodePointer(); currentNodePointer = thisLocation.getImmediateParentPointer(); while (currentNodePointer

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS> actual = pointer.toString(); assertEquals("Evaluating pointer <" + xpath + ">", expected, actual); } protected void assertXPathValueAndPointer(JXPathContext ctx, String xpath, Object expectedValue, String expectedPointer) { assertXPathValue(ctx, xpath, expectedValue); assertXPathPointer(ctx, xpath, expectedPointer); } protected void assertXPathValueIterator(JXPathContext ctx, String xpath, Collection expected) { Collection actual; if (expected instanceof List) { actual = new ArrayList(); } else { actual = new HashSet(); } Iterator it = ctx.iterate(xpath); while (it.hasNext()) { actual.add(it.next()); } assertEquals("Evaluating value iterator <" + xpath + ">", expected, actual); } protected void assertXPathPointerIterator( JXPathContext ctx, String xpath, Collection expected) { Collection actual; if (expected instanceof List) { actual = new ArrayList(); } else { actual = new HashSet(); } Iterator it = ctx.iteratePointers(xpath); while (it.hasNext()) { Pointer pointer = (Pointer) it.next(); actual.add(pointer.toString()); } assertEquals( "Evaluating pointer iterator <" + xpath + ">", expected, actual); } protected void assertDocumentOrder( JXPathContext context, String path1, String path2, int expected) { NodePointer np1 = (NodePointer) context.getPointer(path1); NodePointer np2 = (NodePointer) context.getPointer(path2); int res = np1.compareTo(np2); if (res < 0) { res = -1; } else if (res > 0) { res = 1; } assertEquals( "Comparing paths '" + path1 + "' and '" + path2 + "'", expected, res); } protected void assertXPathValueType( JXPathContext ctx, String xpath, Class clazz) { ctx.setLenient(false); Object actual = ctx.getValue(xpath); assertTrue("Evaluating <" + xpath + "> = " + actual.getClass(), clazz.isAssignableFrom(actual

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import org.apache.commons.jxpath.Pointer; import org.apache.commons.jxpath.ri.model.NodeIterator; import org.apache.commons.jxpath.ri.model.NodePointer; /** * The reference implementation of JXPathContext. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class NamespaceResolver implements Cloneable { final protected NamespaceResolver parent; protected HashMap namespaceMap = new HashMap(); protected HashMap reverseMap; protected NodePointer pointer; private String defaultNamespaceURI; private boolean sealed; public NamespaceResolver(NamespaceResolver parent) { this.parent = parent; } /** * Registers a namespace prefix. * * @param prefix A namespace prefix * @param namespaceURI A URI for that prefix */ public void registerNamespace(String prefix, String namespaceURI) { namespaceMap.put(prefix, namespaceURI); reverseMap = null; } /** * Register a namespace for the expression context. */ public void setNamespaceContextPointer(NodePointer pointer) { this.pointer = pointer; } public Pointer getNamespaceContextPointer() { if (pointer == null && parent != null) { return parent.getNamespaceContextPointer(); } return pointer;

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS> } /** * Given a prefix, returns a registered namespace URI. If the requested * prefix was not defined explicitly using the registerNamespace method, * JXPathContext will then check the context node to see if the prefix is * defined there. See * {@link #setNamespaceContextPointer(Pointer) setNamespaceContextPointer}. * * @param prefix The namespace prefix to look up * @return namespace URI or null if the prefix is undefined. */ public String getNamespaceURI(String prefix) { String uri = (String) namespaceMap.get(prefix); if (uri == null && pointer != null) { uri = pointer.getNamespaceURI(prefix); } if (uri == null && parent != null) { return parent.getNamespaceURI(prefix); } return uri; } public String getPrefix(String namespaceURI) { if (reverseMap == null) { reverseMap = new HashMap(); NodeIterator ni = pointer.namespaceIterator(); if (ni != null) { for (int position = 1; ni.setPosition(position); position++) { NodePointer nsPointer = ni.getNodePointer(); String uri = nsPointer.getNamespaceURI(); String prefix = nsPointer.getName().getName(); if (!"".equals(prefix)) { reverseMap.put(uri, prefix); } } } Iterator it = namespaceMap.entrySet().iterator(); while (it.hasNext()) { Map.Entry entry = (Map.Entry) it.next(); reverseMap.put(entry.getValue(), entry.getKey()); } } String prefix = (String) reverseMap.get(namespaceURI); if (prefix == null && parent != null) { return parent.getPrefix(namespaceURI); } return prefix; } public String getDefaultNamespaceURI() { return defaultNamespaceURI; } public void registerDefaultNamespaceURI(String uri) { this.defaultNamespaceURI = uri; } public boolean isSealed() { return sealed; } public void seal() { sealed = true; if (parent != null) { parent.seal(); } } public Object clone() { try { return super.clone(); } catch (CloneNotSupportedException e) {

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.dynamic; import java.util.Locale; import org.apache.commons.jxpath.DynamicPropertyHandler; import org.apache.commons.jxpath.JXPathBeanInfo; import org.apache.commons.jxpath.JXPathIntrospector; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.model.NodePointer; import org.apache.commons.jxpath.ri.model.NodePointerFactory; import org.apache.commons.jxpath.ri.model.beans.NullPointer; import org.apache.commons.jxpath.util.ValueUtils; /** * Implements NodePointerFactory for Dynamic classes like Map. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class DynamicPointerFactory implements NodePointerFactory { public static final int DYNAMIC_POINTER_FACTORY_ORDER = 800; public int getOrder() { return DYNAMIC_POINTER_FACTORY_ORDER; } public NodePointer createNodePointer( QName name, Object bean, Locale locale) { JXPathBeanInfo bi = JXPathIntrospector.getBeanInfo(bean.getClass()); if (bi.isDynamic()) { DynamicPropertyHandler handler = ValueUtils.getDynamicPropertyHandler( bi.getDynamicPropertyHandlerClass()); return

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS> new DynamicPointer(name, bean, handler, locale); } return null; } public NodePointer createNodePointer( NodePointer parent, QName name, Object bean) { if (bean == null) { return new NullPointer(parent, name); } JXPathBeanInfo bi = JXPathIntrospector.getBeanInfo(bean.getClass()); if (bi.isDynamic()) { DynamicPropertyHandler handler = ValueUtils.getDynamicPropertyHandler( bi.getDynamicPropertyHandlerClass()); return new DynamicPointer(parent, name, bean, handler); } return null; } }

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.axes; import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.compiler.NodeNameTest; import org.apache.commons.jxpath.ri.compiler.NodeTest; import org.apache.commons.jxpath.ri.model.NodeIterator; import org.apache.commons.jxpath.ri.model.NodePointer; /** * EvalContext that walks the "attribute::" axis. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class AttributeContext extends EvalContext { private NodeTest nodeTest; private boolean setStarted = false; private NodeIterator iterator; private NodePointer currentNodePointer; /** * @param parentContext represents the previous step on the path * @param nameTest is the name of the attribute we are looking for */ public AttributeContext(EvalContext parentContext, NodeTest nodeTest) { super(parentContext); this.nodeTest = nodeTest; } public NodePointer getCurrentNodePointer() { return currentNodePointer; } public void reset() { setStarted = false; iterator = null; super.reset(); } public boolean setPosition(int position) { if (position < getCurrentPosition()) { reset(); } while (

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>getCurrentPosition() < position) { if (!nextNode()) { return false; } } return true; } public boolean nextNode() { super.setPosition(getCurrentPosition() + 1); if (!setStarted) { setStarted = true; if (!(nodeTest instanceof NodeNameTest)) { return false; } QName name = ((NodeNameTest) nodeTest).getNodeName(); iterator = parentContext.getCurrentNodePointer().attributeIterator(name); } if (iterator == null) { return false; } if (!iterator.setPosition(iterator.getPosition() + 1)) { return false; } currentNodePointer = iterator.getNodePointer(); return true; } }

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.container; import java.util.Locale; import org.apache.commons.jxpath.Container; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.compiler.NodeTest; import org.apache.commons.jxpath.ri.model.NodeIterator; import org.apache.commons.jxpath.ri.model.NodePointer; import org.apache.commons.jxpath.util.ValueUtils; /** * Transparent pointer to a Container. The getValue() method * returns the contents of the container, rather than the container * itself. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class ContainerPointer extends NodePointer { private Container container; private NodePointer valuePointer; public ContainerPointer(Container container, Locale locale) { super(null, locale); this.container = container; } public ContainerPointer(NodePointer parent, Container container) { super(parent); this.container = container; } /** * This type of node is auxiliary. */ public boolean isContainer() { return true; } public QName getName() { return null; } public Object getBaseValue() { return container; } public boolean isCollection() { Object value = getBaseValue(); return value != null &&

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS> ValueUtils.isCollection(value); } public int getLength() { Object value = getBaseValue(); return value == null ? 1 : ValueUtils.getLength(value); } public boolean isLeaf() { return getValuePointer().isLeaf(); } public Object getImmediateNode() { Object value = getBaseValue(); if (index != WHOLE_COLLECTION) { return index >= 0 && index < getLength() ? ValueUtils.getValue(value, index) : null; } return ValueUtils.getValue(value); } public void setValue(Object value) { // TODO: what if this is a collection? container.setValue(value); } public NodePointer getImmediateValuePointer() { if (valuePointer == null) { Object value = getImmediateNode(); valuePointer = NodePointer.newChildNodePointer(this, getName(), value); } return valuePointer; } public int hashCode() { return System.identityHashCode(container) + index; } public boolean equals(Object object) { if (object == this) { return true; } if (!(object instanceof ContainerPointer)) { return false; } ContainerPointer other = (ContainerPointer) object; return container == other.container && index == other.index; } public NodeIterator childIterator( NodeTest test, boolean reverse, NodePointer startWith) { return getValuePointer().childIterator(test, reverse, startWith); } public NodeIterator attributeIterator(QName name) { return getValuePointer().attributeIterator(name); } public NodeIterator namespaceIterator() { return getValuePointer().namespaceIterator(); } public NodePointer namespacePointer(String namespace) { return getValuePointer().namespacePointer(namespace); } public boolean testNode(NodeTest nodeTest) { return getValuePointer().testNode(nodeTest); } public int compareChildNodePointers( NodePointer pointer1, NodePointer pointer2) { return pointer1.getIndex() - pointer2.getIndex(); } public String getNamespaceURI(String prefix) { return getValuePointer().getNamespaceURI(prefix); } public String asPath() { return parent == null ? "/" : parent.asPath(); } }

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>step.getPredicates()); } return false; } protected boolean areBasicPredicates(Expression predicates[]) { if (predicates != null && predicates.length != 0) { boolean firstIndex = true; for (int i = 0; i < predicates.length; i++) { if (predicates[i] instanceof NameAttributeTest) { if (((NameAttributeTest) predicates[i]) .getNameTestExpression() .isContextDependent()) { return false; } } else if (predicates[i].isContextDependent()) { return false; } else { if (!firstIndex) { return false; } firstIndex = false; } } } return true; } /** * Given a root context, walks a path therefrom and finds the * pointer to the first element matching the path. */ protected Pointer getSingleNodePointerForSteps(EvalContext context) { if (steps.length == 0) { return context.getSingleNodePointer(); } if (isSimplePath()) { NodePointer ptr = (NodePointer) context.getSingleNodePointer(); return SimplePathInterpreter.interpretSimpleLocationPath( context, ptr, steps); } return searchForPath(context); } /** * The idea here is to return a NullPointer rather than null if that's at * all possible. Take for example this path: "//map/key". Let's say, "map" * is an existing node, but "key" is not there. We will create a * NullPointer that can be used to set/create the "key" property. * <p> * However, a path like "//key" would still produce null, because we have * no way of knowing where "key" would be if it existed. * </p> * <p> * To accomplish this, we first try the path itself. If it does not find * anything, we chop off last step of the path, as long as it is a simple * one like child:: or attribute:: and try to evaluate the truncated path. * If it finds exactly one node - create a NullPointer and return. If it * fails, chop off another step and repeat. If it finds more than one

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS> * location - return null. * </p> */ private Pointer searchForPath(EvalContext context) { EvalContext ctx = buildContextChain(context, steps.length, true); Pointer pointer = ctx.getSingleNodePointer(); if (pointer != null) { return pointer; } for (int i = steps.length; --i > 0;) { if (!isSimpleStep(steps[i])) { return null; } ctx = buildContextChain(context, i, true); if (ctx.hasNext()) { Pointer partial = (Pointer) ctx.next(); if (ctx.hasNext()) { // If we find another location - the search is // ambiguous, so we report failure return null; } if (partial instanceof NodePointer) { return SimplePathInterpreter.createNullPointer( context, (NodePointer) partial, steps, i); } } } return null; } /** * Given a root context, walks a path therefrom and builds a context * that contains all nodes matching the path. */ protected EvalContext evalSteps(EvalContext context) { return buildContextChain(context, steps.length, false); } private EvalContext buildContextChain( EvalContext context, int stepCount, boolean createInitialContext) { if (createInitialContext) { context = new InitialContext(context); } if (steps.length == 0) { return context; } for (int i = 0; i < stepCount; i++) { context = createContextForStep( context, steps[i].getAxis(), steps[i].getNodeTest()); Expression predicates[] = steps[i].getPredicates(); if (predicates != null) { for (int j = 0; j < predicates.length; j++) { if (j != 0) { context = new UnionContext(context, new EvalContext[]{context}); } context = new PredicateContext(context, predicates[j]); } } } return context; } /** * Different axes are serviced by different contexts. This method * allocates the right context for the supplied step. */ protected EvalContext createContextForStep(

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.beans; import java.util.Locale; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.model.NodePointer; /** * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class NullPointer extends PropertyOwnerPointer { private QName name; private String id; public NullPointer(QName name, Locale locale) { super(null, locale); this.name = name; } /** * Used for the root node */ public NullPointer(NodePointer parent, QName name) { super(parent); this.name = name; } public NullPointer(Locale locale, String id) { super(null, locale); this.id = id; } public QName getName() { return name; } public Object getBaseValue() { return null; } public boolean isCollection() { return false; } public boolean isLeaf() { return true; } public boolean isActual() { return false; } public PropertyPointer getPropertyPointer() { return new NullPropertyPointer(this); } public NodePointer createPath(JXPathContext context, Object value) { if (parent != null) { return parent.createPath(context,

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS> value).getValuePointer(); } throw new UnsupportedOperationException( "Cannot create the root object: " + asPath()); } public NodePointer createPath(JXPathContext context) { if (parent != null) { return parent.createPath(context).getValuePointer(); } throw new UnsupportedOperationException( "Cannot create the root object: " + asPath()); } public NodePointer createChild( JXPathContext context, QName name, int index) { return createPath(context).createChild(context, name, index); } public NodePointer createChild( JXPathContext context, QName name, int index, Object value) { return createPath(context).createChild(context, name, index, value); } public int hashCode() { return name == null ? 0 : name.hashCode(); } public boolean equals(Object object) { if (object == this) { return true; } if (!(object instanceof NullPointer)) { return false; } NullPointer other = (NullPointer) object; return name == other.name || name != null && name.equals(other.name); } public String asPath() { if (id != null) { return "id(" + id + ")"; } return parent == null ? "null()" : super.asPath(); } public int getLength() { return 0; } }

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS> element of the list is * a Pointer. * * @return A list representing the current context nodes. */ List getContextNodeList(); /** * Returns the current context position. */ int getPosition(); }

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model; import java.util.Locale; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.JXPathException; import org.apache.commons.jxpath.Pointer; import org.apache.commons.jxpath.ri.Compiler; import org.apache.commons.jxpath.ri.JXPathContextReferenceImpl; import org.apache.commons.jxpath.ri.NamespaceResolver; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.compiler.NodeNameTest; import org.apache.commons.jxpath.ri.compiler.NodeTest; import org.apache.commons.jxpath.ri.compiler.NodeTypeTest; import org.apache.commons.jxpath.ri.model.beans.NullPointer; /** * Common superclass for Pointers of all kinds. A NodePointer maps to * a deterministic XPath that represents the location of a node in an * object graph. This XPath uses only simple axes: child, namespace and * attribute and only simple, context-independent predicates. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public abstract class NodePointer implements Pointer { public static final int WHOLE_COLLECTION = Integer.MIN_VALUE; protected int index = WHOLE_COLLECTION;

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS> public static final String UNKNOWN_NAMESPACE = "<<unknown namespace>>"; private boolean attribute = false; private transient Object rootNode; private NamespaceResolver namespaceResolver; /** * Allocates an entirely new NodePointer by iterating through all installed * NodePointerFactories until it finds one that can create a pointer. */ public static NodePointer newNodePointer( QName name, Object bean, Locale locale) { NodePointer pointer = null; if (bean == null) { pointer = new NullPointer(name, locale); return pointer; } NodePointerFactory[] factories = JXPathContextReferenceImpl.getNodePointerFactories(); for (int i = 0; i < factories.length; i++) { pointer = factories[i].createNodePointer(name, bean, locale); if (pointer != null) { return pointer; } } throw new JXPathException( "Could not allocate a NodePointer for object of " + bean.getClass()); } /** * Allocates an new child NodePointer by iterating through all installed * NodePointerFactories until it finds one that can create a pointer. */ public static NodePointer newChildNodePointer( NodePointer parent, QName name, Object bean) { NodePointerFactory[] factories = JXPathContextReferenceImpl.getNodePointerFactories(); for (int i = 0; i < factories.length; i++) { NodePointer pointer = factories[i].createNodePointer(parent, name, bean); if (pointer != null) { return pointer; } } throw new JXPathException( "Could not allocate a NodePointer for object of " + bean.getClass()); } protected NodePointer parent; protected Locale locale; // private NamespaceManager namespaceManager; protected NodePointer(NodePointer parent) { this.parent = parent; } protected NodePointer(NodePointer parent, Locale locale) { this.parent = parent; this.locale = locale; } public NamespaceResolver getNamespaceResolver() { if (namespaceResolver == null && parent != null) { namespaceResolver = parent.getNamespaceResolver(); } return namespaceResolver; } public void setNamespaceResolver(NamespaceResolver namespaceResolver) { this.namespaceResolver = namespaceResolver; } public

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS> NodePointer getParent() { NodePointer pointer = parent; while (pointer != null && pointer.isContainer()) { pointer = pointer.getImmediateParentPointer(); } return pointer; } public NodePointer getImmediateParentPointer() { return parent; } /** * Set to true if the pointer represents the "attribute::" axis. */ public void setAttribute(boolean attribute) { this.attribute = attribute; } /** * Returns true if the pointer represents the "attribute::" axis. */ public boolean isAttribute() { return attribute; } /** * Returns true if this Pointer has no parent. */ public boolean isRoot() { return parent == null; } /** * If true, this node does not have children */ public abstract boolean isLeaf(); /** * @deprecated Please use !isContainer() */ public boolean isNode() { return !isContainer(); } /** * If true, this node is axiliary and can only be used as an intermediate in * the chain of pointers. */ public boolean isContainer() { return false; } /** * If the pointer represents a collection, the index identifies * an element of that collection. The default value of <code>index</code> * is <code>WHOLE_COLLECTION</code>, which just means that the pointer * is not indexed at all. * Note: the index on NodePointer starts with 0, not 1. */ public int getIndex() { return index; } public void setIndex(int index) { this.index = index; } /** * Returns <code>true</code> if the value of the pointer is an array or * a Collection. */ public abstract boolean isCollection(); /** * If the pointer represents a collection (or collection element), * returns the length of the collection. * Otherwise returns 1 (even if the value is null). */ public abstract int getLength(); /** * By default, returns <code>getNode()</code>, can be overridden to * return a "canonical" value, like for instance a DOM element should * return its string value. */ public Object getValue() { NodePointer valuePointer = getValuePointer

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>(); if (valuePointer != this) { return valuePointer.getValue(); } // Default behavior is to return the same as getNode() return getNode(); } /** * If this pointer manages a transparent container, like a variable, * this method returns the pointer to the contents. * Only an auxiliary (non-node) pointer can (and should) return a * value pointer other than itself. * Note that you probably don't want to override * <code>getValuePointer()</code> directly. Override the * <code>getImmediateValuePointer()</code> method instead. The * <code>getValuePointer()</code> method is calls * <code>getImmediateValuePointer()</code> and, if the result is not * <code>this</code>, invokes <code>getValuePointer()</code> recursively. * The idea here is to open all nested containers. Let's say we have a * container within a container within a container. The * <code>getValuePointer()</code> method should then open all those * containers and return the pointer to the ultimate contents. It does so * with the above recursion. */ public NodePointer getValuePointer() { NodePointer ivp = getImmediateValuePointer(); return ivp == this ? this : ivp.getValuePointer(); } /** * @see #getValuePointer() * * @return NodePointer is either <code>this</code> or a pointer * for the immediately contained value. */ public NodePointer getImmediateValuePointer() { return this; } /** * An actual pointer points to an existing part of an object graph, even * if it is null. A non-actual pointer represents a part that does not exist * at all. * For instance consider the pointer "/address/street". * If both <em>address</em> and <em>street</em> are not null, * the pointer is actual. * If <em>address</em> is not null, but <em>street</em> is null, * the pointer is still actual. * If <em>address</em> is null, the pointer is not actual. * (In JavaBeans) if <em>address</em> is not a property of the root bean,

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS> * a Pointer for this path cannot be obtained at all - actual or otherwise. */ public boolean isActual() { return index == WHOLE_COLLECTION || index >= 0 && index < getLength(); } /** * Returns the name of this node. Can be null. */ public abstract QName getName(); /** * Returns the value represented by the pointer before indexing. * So, if the node represents an element of a collection, this * method returns the collection itself. */ public abstract Object getBaseValue(); /** * Returns the object the pointer points to; does not convert it * to a "canonical" type. * * @deprecated 1.1 Please use getNode() */ public Object getNodeValue() { return getNode(); } /** * Returns the object the pointer points to; does not convert it * to a "canonical" type. Opens containers, properties etc and returns * the ultimate contents. */ public Object getNode() { return getValuePointer().getImmediateNode(); } public Object getRootNode() { if (rootNode == null) { rootNode = parent == null ? getImmediateNode() : parent.getRootNode(); } return rootNode; } /** * Returns the object the pointer points to; does not convert it * to a "canonical" type. */ public abstract Object getImmediateNode(); /** * Converts the value to the required type and changes the corresponding * object to that value. */ public abstract void setValue(Object value); /** * Compares two child NodePointers and returns a positive number, * zero or a positive number according to the order of the pointers. */ public abstract int compareChildNodePointers( NodePointer pointer1, NodePointer pointer2); /** * Checks if this Pointer matches the supplied NodeTest. */ public boolean testNode(NodeTest test) { if (test == null) { return true; } if (test instanceof NodeNameTest) { if (isContainer()) { return false; } NodeNameTest nodeNameTest = (NodeNameTest) test; QName testName = nodeNameTest.getNodeName(); QName nodeName = getName(); if (nodeName == null) { return false; } String testPrefix = test

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>Name.getPrefix(); String nodePrefix = nodeName.getPrefix(); if (!equalStrings(testPrefix, nodePrefix)) { String testNS = getNamespaceURI(testPrefix); String nodeNS = getNamespaceURI(nodePrefix); if (!equalStrings(testNS, nodeNS)) { return false; } } if (nodeNameTest.isWildcard()) { return true; } return testName.getName().equals(nodeName.getName()); } return test instanceof NodeTypeTest && ((NodeTypeTest) test).getNodeType() == Compiler.NODE_TYPE_NODE && isNode(); } private static boolean equalStrings(String s1, String s2) { return s1 == s2 || s1 != null && s1.equals(s2); } /** * Called directly by JXPathContext. Must create path and * set value. */ public NodePointer createPath(JXPathContext context, Object value) { setValue(value); return this; } /** * Remove the node of the object graph this pointer points to. */ public void remove() { // It is a no-op // System.err.println("REMOVING: " + asPath() + " " + getClass()); // printPointerChain(); } /** * Called by a child pointer when it needs to create a parent object. * Must create an object described by this pointer and return * a new pointer that properly describes the new object. */ public NodePointer createPath(JXPathContext context) { return this; } /** * Called by a child pointer if that child needs to assign the value * supplied in the createPath(context, value) call to a non-existent * node. This method may have to expand the collection in order to assign * the element. */ public NodePointer createChild( JXPathContext context, QName name, int index, Object value) { throw new JXPathException("Cannot create an object for path " + asPath() + "/" + name + "[" + (index + 1) + "]" + ", operation is not allowed for this type of node"); } /** * Called by a child pointer when it needs to create a parent object for a

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS> * non-existent collection element. It may have to expand the collection, * then create an element object and return a new pointer describing the * newly created element. */ public NodePointer createChild(JXPathContext context, QName name, int index) { throw new JXPathException("Cannot create an object for path " + asPath() + "/" + name + "[" + (index + 1) + "]" + ", operation is not allowed for this type of node"); } /** * Called to create a non-existing attribute */ public NodePointer createAttribute(JXPathContext context, QName name) { throw new JXPathException("Cannot create an attribute for path " + asPath() + "/@" + name + ", operation is not allowed for this type of node"); } /** * If the Pointer has a parent, returns the parent's locale; otherwise * returns the locale specified when this Pointer was created. */ public Locale getLocale() { if (locale == null) { if (parent != null) { locale = parent.getLocale(); } } return locale; } /** * Returns true if the selected locale name starts * with the specified prefix <i>lang</i>, case-insensitive. */ public boolean isLanguage(String lang) { Locale loc = getLocale(); String name = loc.toString().replace('_', '-'); return name.toUpperCase().startsWith(lang.toUpperCase()); } // /** // * Installs the supplied manager as the namespace manager for this node // * pointer. The {@link #getNamespaceURI(String) getNamespaceURI(prefix)} // * uses this manager to resolve namespace prefixes. // * // * @param namespaceManager // */ // public void setNamespaceManager(NamespaceManager namespaceManager) { // this.namespaceManager = namespaceManager; // } // // public NamespaceManager getNamespaceManager() { // if (namespaceManager != null) { // return namespaceManager; // } // if (parent != null) { // return parent.getNamespaceManager(); // } // return null; // } // /** * Returns a NodeIterator that iterates

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS> over all children or all children * that match the given NodeTest, starting with the specified one. */ public NodeIterator childIterator( NodeTest test, boolean reverse, NodePointer startWith) { NodePointer valuePointer = getValuePointer(); return valuePointer == null || valuePointer == this ? null : valuePointer.childIterator(test, reverse, startWith); } /** * Returns a NodeIterator that iterates over all attributes of the current * node matching the supplied node name (could have a wildcard). * May return null if the object does not support the attributes. */ public NodeIterator attributeIterator(QName qname) { NodePointer valuePointer = getValuePointer(); return valuePointer == null || valuePointer == this ? null : valuePointer.attributeIterator(qname); } /** * Returns a NodeIterator that iterates over all namespaces of the value * currently pointed at. * May return null if the object does not support the namespaces. */ public NodeIterator namespaceIterator() { return null; } /** * Returns a NodePointer for the specified namespace. Will return null * if namespaces are not supported. * Will return UNKNOWN_NAMESPACE if there is no such namespace. */ public NodePointer namespacePointer(String namespace) { return null; } /** * Decodes a namespace prefix to the corresponding URI. */ public String getNamespaceURI(String prefix) { return null; } /** * Returns the namespace URI associated with this Pointer. */ public String getNamespaceURI() { return null; } /** * Returns true if the supplied prefix represents the * default namespace in the context of the current node. */ protected boolean isDefaultNamespace(String prefix) { if (prefix == null) { return true; } String namespace = getNamespaceURI(prefix); return namespace != null && namespace.equals(getDefaultNamespaceURI()); } protected String getDefaultNamespaceURI() { return null; } /** * Locates a node by ID. */ public Pointer getPointerByID(JXPathContext context, String id) { return context.getPointerByID(id); } /** * Locates a node by key and value. */ public Pointer getPointerByKey( JXPath

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>Context context, String key, String value) { return context.getPointerByKey(key, value); } /** * Returns an XPath that maps to this Pointer. */ public String asPath() { // If the parent of this node is a container, it is responsible // for appended this node's part of the path. if (parent != null && parent.isContainer()) { return parent.asPath(); } StringBuffer buffer = new StringBuffer(); if (parent != null) { buffer.append(parent.asPath()); } if (buffer.length() == 0 || buffer.charAt(buffer.length() - 1) != '/') { buffer.append('/'); } if (attribute) { buffer.append('@'); } buffer.append(getName()); if (index != WHOLE_COLLECTION && isCollection()) { buffer.append('[').append(index + 1).append(']'); } return buffer.toString(); } public Object clone() { try { NodePointer ptr = (NodePointer) super.clone(); if (parent != null) { ptr.parent = (NodePointer) parent.clone(); } return ptr; } catch (CloneNotSupportedException ex) { // Of course it is supported ex.printStackTrace(); } return null; } public String toString() { return asPath(); } public int compareTo(Object object) { // Let it throw a ClassCastException NodePointer pointer = (NodePointer) object; if (parent == pointer.parent) { return parent == null ? 0 : parent.compareChildNodePointers(this, pointer); } // Task 1: find the common parent int depth1 = 0; NodePointer p1 = this; while (p1 != null) { depth1++; p1 = p1.parent; } int depth2 = 0; NodePointer p2 = pointer; while (p2 != null) { depth2++; p2 = p2.parent; } return compareNodePointers(this, depth1, pointer, depth2); } private int compareNodePointers( NodePointer p1, int depth1, NodePointer p2, int

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS> depth2) { if (depth1 < depth2) { int r = compareNodePointers(p1, depth1, p2.parent, depth2 - 1); return r == 0 ? -1 : r; } if (depth1 > depth2) { int r = compareNodePointers(p1.parent, depth1 - 1, p2, depth2); return r == 0 ? 1 : r; } if (p1 == null && p2 == null) { return 0; } if (p1 != null && p1.equals(p2)) { return 0; } if (depth1 == 1) { throw new JXPathException( "Cannot compare pointers that do not belong to the same tree: '" + p1 + "' and '" + p2 + "'"); } int r = compareNodePointers(p1.parent, depth1 - 1, p2.parent, depth2 - 1); if (r != 0) { return r; } return p1.parent.compareChildNodePointers(p1, p2); } /** * Print internal structure of a pointer for debugging */ public void printPointerChain() { printDeep(this, ""); } private static void printDeep(NodePointer pointer, String indent) { if (indent.length() == 0) { System.err.println( "POINTER: " + pointer + "(" + pointer.getClass().getName() + ")"); } else { System.err.println( indent + " of " + pointer + "(" + pointer.getClass().getName() + ")"); } if (pointer.getImmediateParentPointer() != null) { printDeep(pointer.getImmediateParentPointer(), indent + " "); } } }

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.jdom; import java.util.Collections; import java.util.List; import org.apache.commons.jxpath.ri.compiler.NodeTest; import org.apache.commons.jxpath.ri.model.NodeIterator; import org.apache.commons.jxpath.ri.model.NodePointer; import org.jdom.Document; import org.jdom.Element; /** * An iterator of children of a JDOM Node. * * @author Dmitri Plotnikov * @version $Revision$ $Date$ */ public class JDOMNodeIterator implements NodeIterator { private NodePointer parent; private NodeTest nodeTest; private boolean reverse; private int position = 0; private int index = 0; private List children; private Object child; public JDOMNodeIterator( NodePointer parent, NodeTest nodeTest, boolean reverse, NodePointer startWith) { this.parent = parent; if (startWith != null) { this.child = startWith.getNode(); } // TBD: optimize me for different node tests Object node = parent.getNode(); if (node instanceof Document) { this.children = ((Document) node).getContent(); } else if (node instanceof Element) { this.children = ((Element) node).getContent(); } else { this.children = Collections

JxPath, 4

<FILEB>
<CHANGES>
protected static String findEnclosingAttribute(Node n, String attrName) {
<CHANGEE>
<CHANGES>
String attr = e.getAttribute(attrName);
<CHANGEE>
<CHANGES>
protected String getLanguage() {
return findEnclosingAttribute(node, "xml:lang");
}
<CHANGEE>
<CHANGES>
if (node.getNodeType() == Node.COMMENT_NODE) {
String text = ((Comment) node).getData();
return text == null? "" : text.trim();
}
<CHANGEE>
<CHANGES>
return "";
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "xml:space"));
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
return text == null? "" : trim? text.trim() : text;
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
return buf.toString();
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
StringBuffer buf = new StringBuffer();
for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) {
NodePointer ptr = children.getNodePointer();
if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
buf.append(ptr.getValue());
}
}
return buf.toString();
<CHANGEE>
<CHANGES>
String result = null;
<CHANGEE>
<CHANGES>
result = ((Text) node).getText();
<CHANGEE>
<CHANGES>
<CHANGEE>
<CHANGES>
result = ((ProcessingInstruction) node).getData();
<CHANGEE>
<CHANGES>
boolean trim =!"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
return result!= null && trim? result.trim() : result;
<CHANGEE>
<CHANGES>
return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE);
}
protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) {
<CHANGEE>
<CHANGES>
String attr = e.getAttributeValue(attrName, ns);
<CHANGEE>
<CHANGES>
}<CHANGEE>
<FILEE>
<FILEB> return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix <i>lang</i>. * If no node has this prefix, calls <code>super.isLanguage(lang)</code>. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } <CHANGES> protected String getLanguage() { Node n = node; <CHANGEE> while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; <CHANGES> String attr = e.getAttribute("xml:lang"); <CHANGEE> if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } <CHANGES> <CHANGEE> /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } <SCANS>.EMPTY_LIST; } this.nodeTest = nodeTest; this.reverse = reverse; } public NodePointer getNodePointer() { if (child == null) { if (!setPosition(1)) { return null; } position = 0; } return new JDOMNodePointer(parent, child); } public int getPosition() { return position; } public boolean setPosition(int position) { while (this.position < position) { if (!next()) { return false; } } while (this.position > position) { if (!previous()) { return false; } } return true; } /** * This is actually never invoked during the normal evaluation * of xpaths - an iterator is always going forward, never backwards. * So, this is implemented only for completeness and perhaps for * those who use these iterators outside of XPath evaluation. */ private boolean previous() { position--; if (!reverse) { while (--index >= 0) { child = children.get(index); if (testChild()) { return true; } } } else { for (; index < children.size(); index++) { child = children.get(index); if (testChild()) { return true; } } } return false; } private boolean next() { position++; if (!reverse) { if (position == 1) { index = 0; if (child != null) { index = children.indexOf(child) + 1; } } else { index++; } for (; index < children.size(); index++) { child = children.get(index); if (testChild()) { return true; } } return false; } else { if (position == 1) { index = children.size() - 1; if (child != null) { index = children.indexOf(child) - 1; } } else { index--; } for (; index >= 0; index--) { child = children.get(index); if (testChild()) { return true; } } return false;